私は暇な時間に少しJSを学ぼうとしていますが、私はこのテーマをテーマにしていました。私はperson.fullDetail();
を実行傾ける理由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();
は誰も教えてもらえますか?
ご使用のバージョンのコードでご意見をお寄せいただければ、ありがとうございます。ありがとうございます。
をあなたが定義する前にインスタンスを作成している、これを試してみてください機能! –
@ DanielA.White Hoistingはこのうちのいくつかを修正しました – Feathercrown
ホイストはここでのいくつかの機能にのみ適用されます。 – ssube