Person.prototype
和Object.create(Person.prototype)
有什麼區別?我可以使用他們每個人嗎?Javascript Object prototype and Object.create method
function Person(name) {
this.name = name;
}
Person.prototype.copy = function() {
return new this.constructor(this.name);
};
// define the Student class
function Student(name) {
Person.call(this, name);
}
// inherit Person
Student.prototype = Person.prototype;
//Student.prototype = Object.create(Person.prototype);
http://blog.slaks.net/2013-09-03/traditional-inheritance-in-javascript/ – SLaks
參見:[使用「Object.create」而不是「新」](http://stackoverflow.com/q/2709612/4639281) –