Object.create(proto, [propertiesObject])
bash
let proto = {};
let createdObject = Object.create(proto);
console.log(createdObject.__proto__ === proto);
复制代码
Object.defineProperties(obj, props)
函数
let obj = {};
Object.defineProperties(obj, {
"name": {
value: "Cat",
enumerable: true
}
});
console.log(obj);
复制代码
let createdObject2 = Object.create({}, {
"name": {
value: "Cat",
enumerable: true
}
});
console.log(createdObject2.hasOwnProperty("name"));
复制代码