ES6 的类(class):
一、类的数据类型是函数function
class Point{} typeof Point = "function" // 类的数据类型function
let point = new Point() // 类的使用
二、一次向类中添加多个方法
Object.assign(Point.prototype,{
toString(){},
toValue(){}
})
三、类可以通过extends继承其它类:ColorPoint继承了Point
class ColorPoint extends Point{ constructor(x,y,color){
super(x,y); // 调用父类的constructon(x,y)
this.color = color
}
toString() {
return this.color + super.toString() // 调用父类的toString()
}
}
代码中都出现了super关键字,它在这里指的是父类的构造函数,用来新建父类的this。