Skip to content

Instantly share code, notes, and snippets.

@zhangwc
Created December 24, 2013 08:41
Show Gist options
  • Save zhangwc/8110461 to your computer and use it in GitHub Desktop.
Save zhangwc/8110461 to your computer and use it in GitHub Desktop.
function Person(name) {
this.name = name;
};
Person.prototype = new Object({
getName: function() {
return this.name;
}
});
Person.prototype.constructor = Person; // 这里需要使用Person来替换掉Object。
var p = new Person("ZhangSan");
console.log(p.constructor === Person); // true
console.log(Person.prototype.constructor === Person); // true
console.log(p.constructor.prototype.constructor === Person); // true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment