类中包含constructor()构造
类中方法名在前,省略function关键字
class Star{
constructor(arg) {
}
say(){
}
}
继承extends与super()指向
如下,父类自己的名字叫“张三”
子类叫父类“爸爸”
使用super()指向修改父类变量
super()调用一定要在this调用前面
class Father{
constructor(name) {
this.name="张三"
}
money(){
console.log("100元");
}
sayName(){
console.log(this.name);
}
}
class Son extends Father{
constructor(fname) {
super().name=fname
}
}
// new Father()
let son=new Son("爸爸")
son.sayName()
this指向
constructor中的this指向的是对象实例
普通方法中的this指向的是调用者