Object构造函数的方法 之 Object.create
Object.create(
proto
,
[
propertiesObject
]
)
创建一个新对象,使用现有的对象来提供新创建的对象的
__proto__
返回值
一个新对象,带着指定的原型对象和属性
JavaScript Demo: 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 = ‘HY’
me.isHuman = true
me.printIntroduction();
Demo:图解
示例
1)
创建对象的方式不同
new Object() 通过构造函数来创建对象, 添加的属性是在自身实例上
Object.create() es6创建对象的另一种方式, 可以理解为继承一个对象&#