在我的業餘時間,我嘗試學習一點JS,但我堅持主題的主題。JS原型和繼承
var person = new Person("Bob", "Smith", 52);
var teacher = new Teacher("Adam", "Greff", 209);
function Humans(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
function Person(firstName, lastName, age) {
Humans.call(this, firstName, lastName);
this.age = age;
}
Person.prototype = Object.create(Humans.prototype);
Person.prototype.fullDetail = function() {
return this.firstName + " " + this.lastName + " " + this.age;
};
function Teacher(firstName, lastName, roomNumber) {
Humans.call(this, firstName, lastName);
this.room = roomNumber;
}
Teacher.prototype = Object.create(Humans.prototype);
Teacher.prototype.fullDetail = function() {
return this.firstName + " " + this.lastName + " " + this.room;
};
person.fullDetail();
任何人能告訴我,爲什麼我不能執行person.fullDetail();
?
如果您可以對您的代碼版本進行一些評論,我將非常感激,謝謝。
你定義之前創建的實例功能! –
@ DanielA.White起重修復了部分此類 – Feathercrown
起重僅適用於此處的一些功能。 – ssube