Created
December 24, 2013 08:41
-
-
Save zhangwc/8110461 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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