美文网首页
Object.create() 与 new Object()的区

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

作者: 尤蛊 | 来源:发表于2020-08-26 18:03 被阅读0次

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);

相关文章

网友评论

      本文标题:Object.create() 与 new Object()的区

      本文链接:https://www.haomeiwen.com/subject/xisfsktx.html