ES6中对象扩展的关键字super

super关键字用来访问到对象的原型:

const obj = {name:'xiaoming'};

const cObj = {
  say() {     // 注意此处只能用对象的简写方式才能访问,
             //若此处用say:function () 或者箭头函数,均会报错
    console.log(`My name is $(super.name)`);
}
}

Obj.setPrototypeof(cObj,obj); //将cObj的原型改为obj;

cObj.say(); // My name is xiaoming

 

你可能感兴趣的:(Es6,super关键字,setPrototype())