通过一段代码理解es6继承;

class animal{
    constructor(props){
        this.name = 'xiaoniao' || props.name
    }
    eat(){
        console.log(this.name+ 'is eating')
    }
}

class birds extends animal{
    constructor(props){
        super(props);
    }
    fly(){
        console.log(this.name+' is flying')
    }
}
var ying = new birds(); //实例化一个ying对象
ying.fly(); //调用birds的fly方法
ying.eat(); //调用eat方法继承自animal 这个类

这里class关键字是es6中特有的,与java语言类似, 也可以用extends 关键字实现继承; 实例化一个niao对象;这个对象继承了animal里面eat方法;自己扩展了fly方法;

原文地址:https://www.cnblogs.com/qqfontofweb/p/7568750.html