Object.create() 与 new Object()的区别

object.create(proto, propertiesObject)

protonull时,创建一个空对象,没有原型

const person = Object.create(null)
console.log(person);

创建一个新的对象,他的原型指向接收的参数对象。

const human = {
  name: "danae",
  isHuman: true,
  printIntroduction: function () {
    console.log(`My name is ${this.name}. Am I human? ${this.isHuman}`);
  }
};
var person = Object.create(human)
console.log(person);

new Object()

创建一个新的对象,他的原型指向Object.prototype

const person = new Object()
console.log(person);
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。