原型(JS)
- 代码:
class Student {
constructor(name, score) {
this.name = name;
this.score = score;
}
introduce() {
console.log(`我是${this.name}, 考了${this.score}分。`);
}
}
const student = new Student("Jujuxiaer, 92");
console.log('student', student);
student.introduce();
-
输出结果:
-
其中 Student.prototype === student.proto 为true,Student.prototype为显示原型,student.__proto__为隐式原型。