当我们可以直接分配对象时,为什么要使用 Object.create() ?

问题描述

const person = {
  isHuman: false,printIntroduction: function() {
    console.log(`My name is ${this.name}. Am I human? ${this.isHuman}`);
  }
};

const me = Object.create(person);

me.name = 'Matthew'; // "name" is a property set on "me",but not on "person"
me.isHuman = true; // inherited properties can be overwritten

me.printIntroduction();

而不是写:

const me = Object.create(person);

为什么不写

const me = person;

相反?我一直看到这个,但仍然不明白。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)