es6:class extends super

it2024-08-08  39

<script>

    class People{

        constructor(name='哇哇'){

            this.name=name

        }

 

        speak(age=12){

            console.log(`名字:${this.name},年龄:${age}`)

        }

    }

 

    class another extends People{

        speak(){

            super.speak();

            console.log(`他的名字叫${this.name}`)

        }

    }

 

    const man=new People();

    man.speak(14);//名字:哇哇,年龄:14

 

    const say=new another('旺旺');

    say.speak();//名字:旺旺,年龄:12     他的名字叫旺旺

</script>

最新回复(0)