Object.create() 与 new Object()的区
2020-08-26 本文已影响0人
尤蛊
object.create(proto, propertiesObject)
当proto
为null
时,创建一个空对象,没有原型
const person = Object.create(null)
console.log(person);
![](https://img.haomeiwen.com/i3915633/d4200b0351efa46e.jpg)
创建一个新的对象,他的原型指向接收的参数对象。
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);
![](https://img.haomeiwen.com/i3915633/937af1b54567a930.jpg)
new Object()
创建一个新的对象,他的原型指向Object.prototype
const person = new Object()
console.log(person);
![](https://img.haomeiwen.com/i3915633/286a99dc1a496e8c.jpg)