乐趣区

关于javascript:class继承

<!--js 文件 -->
<!--class 继承类 -->
class People{constructor(name,age){
        this.name = name;
        this.age = age;
    },
    sayHide(){
        console.log(` 姓名:${this.name}, 年龄 ${this.age}`
        )
    }
}

<!-- 通过类 new 一个实例 / 对象 -->
const xiaoming = new People('xiaoming','19');
xiaoming.sayHide();

class Student extends People{constructor(name,number){super(name);
        this.number = number;
    },
}
const wang = new People('wang',1);
退出移动版