Skip to content

Instantly share code, notes, and snippets.

@hjzheng
Created July 5, 2014 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hjzheng/b5758c37b70b9acba093 to your computer and use it in GitHub Desktop.
Save hjzheng/b5758c37b70b9acba093 to your computer and use it in GitHub Desktop.
JavaScript继承(原型继承)
//JavaScript 原型继承
function extend(obj){
var F = function(){};
F.prototype = obj;
return new F();
}
var obj = {
name: "xxxx"
};
var sub = extend(obj);
console.log(sub.name);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment