<script>
    //父类
    class Person{
        constructor(name){
            this.name = name
        }

        showName(){
            console.log(`父类名字:${this.name}`)
        }

    }
    //子类
    class Student extends Person{
        constructor(name,skill){
            super(name)
            this.skill = skill
        }
        showName(){
            super.showName();//父级的方法执行
            console.log(`子类名字:${this.name}`)
        }
        showSkill(){
            return `技能:${this.skill}`
        }
    }

    let s = new Student("吾爱博客","逃学")
    console.log(s.skill,s.name)
    s.showName()

</script>

版权声明:本文为原创文章,版权归 吾爱博客 所有,转载请联系博主获得授权!
本文地址:https://www.52bd.net/html/161.html

发表评论

正在加载 Emoji
×