<script>
window.onload = function(){
// es6中的继承,就是类和类之间的继承,通过extends和super()方法实现继承
// Person类
class Person {
sleep(){
console.log('time to sleep');
}
constructor(name){
this.name = name
}
}
// Stu类继承Person类
class Stu extends Person{
constructor(score,name){
super(name)
this.score = score
}
}
let stu1 = new Stu(99,'kk')
console.log(stu1); // Stu {name: 'kk', score: 99}
}
</script>
JS中ES6的继承方法
最新推荐文章于 2025-06-05 23:59:04 发布