ECMAScriptECMAScript6初特色的累

class Animal{
    constructor(name){
        this.name = name;
    }
    get name(){
        return this._name;
    }
    set name(val){
        this._name = val;
    }
    run(area){
        console.log(`在${area}奔跑`);
    }
    static hunt(food){
        console.log(`捕食${food}`);
    }
}
class Lion extends Animal{
    constructor(name,desc){
        super(name);
        this._desc = desc;
    }
    get desc(){
        return this._desc;
    }
    set desc(val){
        this._desc = val;
    }
}
let lion = new Lion('非洲雄狮','大型猫科动物');
console.log('lion',lion);
lion.run('非洲草原');
Lion.hunt('野牛');

  假使get、set都尚未或还出,则属性是可读而写的。

  假如单暴发get,则属性是只有读之,写会扔大。

  假设唯有set,则属性是只写的,读会得到undefined。