JS——Object.create()

2019-04-22  本文已影响0人  benbensheng

将一个对象绑定到实例化对象的原型

let person = {
  isHuman: false,
  printIntroduction: function () {
    console.log(this.isHuman);
  }
};

let me = Object.create(person);
me.name = "Matthew"; 
me.isHuman = true; 
me.printIntroduction();  // true
console.log(me.__proto__.isHuman);  //false

console.log(me);

image.png
上一篇 下一篇

猜你喜欢

热点阅读