Skip to content

Instantly share code, notes, and snippets.

@xuanfeng
Last active January 3, 2016 02:39
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 xuanfeng/8396835 to your computer and use it in GitHub Desktop.
Save xuanfeng/8396835 to your computer and use it in GitHub Desktop.
通过原型继承创建一个新对象
function inherit(p){
if(p ==null) throw TypeError();
if(Object.create){
return Object.create(p);
}
var t = typeof p;
if(t !== "object" && t !== "function") throwTypeError();
function f(){};
f.prototype = p;
return new f();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment