ES6class类继承

    class Animal {
        constructor(props) {
            this.name = props.name || '未知'
        }
        eat() {
            console.log(this.name + '在吃东西')
        }
    }

    class Bird extends Animal {
        constructor(props) {
            super(props)
            this.type = props.type || '未知'
        }

        fly() {
            console.log(this.name + '在飞。。。。')
        }
    }
    var myBird = new Bird({name:'鹦鹉'})
    myBird.eat()
    myBird.fly()

 

你可能感兴趣的:(es新特性)