在我的业余时间,我尝试学习一点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