Object.prototype.constructor
所有的对象都会从原型上继承一个constructor属性,Object.prototype.constructor返回实例对象的构造函数的引用。
Object.assign()
完成对象的复制【浅拷贝】
const targetObj = Object.assign({}, userInfo)
console.log("targetObj", targetObj)
Object.create()
创建一个新的对象,可以传入现有的对象的属性,作为新对象的属性。
const userInfo = {
count: 100,
num: null,
printIntroduction: function () {
console.log(`My name is ${this.name}. ${this.count},${this.num}-${this. age}`);
}
}
const me = Object.create(userInfo);
me.name = "duxin";
me.age = 28;
console.log(me.printIntroduction()); // My name is duxin. 100,null-28
Object.entries()
返回对象的键值对数组
console.log(Object.entries(targetObj)); // [ [ 'count', 100 ], [ 'num', null ], [ 'printIntroduction', [Function: printIntroduction] ]]
for (const [key, value] of Object.entries(targetObj)) {
console.log(key,value); // count: 100
}
Object.freeze()
冻结一个对象,不能修改或者删除该对象的属性。
Object.fromEntries()
把键值数组转化为对象。
Object.getOwnPropertyDescriptor()、Object.getOwnPropertyDescriptors()
Object.getOwnPropertyDescriptor()判断某个属性是否是该对象自身的属性,
Object.getOwnPropertyDescriptors()返回对象所有的属性【包含属性值】