函数
function Student(name) {
this.name = name;
}
Student.prototype.hello => alert("name is "+ this.name);
Class类
class Student {
constructor(name) {
this.name = name;
}
hello() {
alert('name is '+this.name);
}
}
class采用constructor
构造一个对象
class继承
class的继承十分方便,引入extends Obj
就可以了
class Student extends StudentList {}
extends
表示继承的原型链来自于StudentList
super()
将this指向该对象,原型继承
class Cat extends Animal {
constructor(name){
super();
this.name = name;
}
say() {
alert('Hello,' + this.name + '!')
}
}