ES6之面向对象

关键词:面向对象

es6新增了类这个语法糖

    // 类
    class Cat{
        constructor(name){
            this.name = name;
        }
        getName(){
            return this.name
        }
    }
    // 继承
    class Dog extends Cat{
        constructor(color,name,...rest){
         super (name);
         this.color = color;
        }
        showColor(){
               return this.color;
        }
    }

    var c1 = new Cat('张无梦');
    console.log(c1.getName());
    var d1 = new Dog('赵归真','gray');
    console.log(d1.getName());
    console.log(d1.showColor());
    console.log(c1.getName());

你可能感兴趣的:(ES6之面向对象)