is
Object.is 比较两个数是否相等
可以用来判断一个值是不是NaN
console.log(Object.is(100,100));
console.log(Object.is(NaN,NaN));
console.log(NaN === NaN);
assign
合并对象
const obj1 = {
a:1,
b:2,
c:3
}
const obj2 = {
a:2,
b:3,
d:4
}
console.log(Object.assign(obj1,obj2));
getPrototypeof和setPrototypeof
获取/设置原型对象
原型对象只能是一个对象,当传入多个对象时,会合并对象,类似于对象合并之后再赋值
console.log(Object.setPrototypeOf(obj1,obj2));
console.log(Object.getPrototypeOf(obj1));
fromEntries
let arr = [
[1, 2],
[2, 4],
[3, 6, 4, 8]
]
let result = Object.fromEntries(arr);
console.log(result);
const m = new Map();
m.set('name', 'zhangsan');
let result1 = Object.fromEntries(m);
console.log(result1);