目录
Object.assign(target, source1, source2..)
对象的简写方式
let username = "kobe";
let age = 18;
let obj = {
username, // 同名的属性可以省略不写
age,
// getName:function(){}
getName() { // 可以省略函数的function
return this.username;
}
}
console.log(obj) // {usernaem:"kobe",age:18,getName:f}
console.log(obj.getName()) // kobe
Object.is(v1, v2)
判断2个数据是否完全相等,以字符串的方式比较
console.log(0 == -0); // true
console.log(NaN == NaN); // false
console.log(Object.is(0, -0)); // false
console.log(Object.is(NaN, NaN)); // true
Object.assign(target, source1, source2..)
将源对象的属性复制到目标对象上
let obj = {};
let obj1 = {
username: 'anverson',
age: 42
};
let obj2 = {money:5000}
Object.assign(obj, obj1,obj2);
console.log(obj) // {username: "anverson", age: 42,money:5000}
直接操作 __proto__ 属性
let obj2 = {};
obj2.__proto__ = obj1;
let obj3 = {};
let obj4 = {
qian: 50000
};
obj3.__proto__ = obj4;
console.log(obj3.qian) // 50000