对象方法扩展
作用
- 对象的扩展运算符…将参数对象中的所有可遍历属性,拷贝到当前对象中
特点
- object.is :判断两个值是否完全相等
js
console.log(Object.is(100, 100)); // true
console.log(Object.is(NaN, NaN)); // true
console.log(NaN === NaN); // false
- object.assign:对象的合并
js
const obj1 = { name: '2', age: 3 };
const obj2 = { gender: '男', age: 30 };
console.log(Object.assign(obj1, obj2)); // {name: '2', age: 30, gender: '男'}
- object.setPrototypeof、object.getPrototypeof:设置/获取原型对象
js
const school = {
name: '河南大学',
};
const citys = {
xiaoqu: ['郑州', '开封'],
};
Object.setPrototypeOf(school, citys);
console.log(school);
console.log(Object.getPrototypeOf(school));