const print = require('./print.js');class Student { constructor(name) { this.name = name;
}
hello() {
alert('Hello, ' + this.name + '!');
}
}class PrimaryStudent extends Student { constructor(name, grade) { super(name); // 記得用super調用父類的構造方法!
this.grade = grade;
}
myGrade() {
print('I am at grade ' + this.grade);
}
}let a = new PrimaryStudent({ name: 'tst', grade: 100})
print(Student.prototype.isPrototypeOf(a));
print(Student.isPrototypeOf(a));
print(a instanceof Student);res:truefalsetrue對比原型式繼承的方式var o1 = {};
var o2 = Object.create(o1);
var o3 = Object.create(o2);o2.isPrototypeOf(o3) // trueo1.isPrototypeOf(o3) // true為什么會有不同的結果
isPrototypeOf的問題
皈依舞
2018-09-17 06:33:22