es6对象

对象赋值

let name='zhang';
let age=30;
let obj={name,age};
console.log(obj);//{name: "zhang", age: 30}

let key='skill';
var obj={
    [key]:'web'  
};
console.log(obj)//{skill: "web"}

自定义对象方法

let obj={
    add:function(a,b){
        return a+b;
    }
};
console.log(obj.add(1,2));//3

is()方法

let obj1={'name':'zhang'};
let obj2={'name':'zhang'};
console.log(obj1.name===obj2.name);//true
console.log(Object.is(obj1.name,obj2.name));//true

//===同值相等,is严格相等
console.log(+0===-0);//true
console.log(NaN===NaN);//false
console.log(Object.is(+0,-0));//false
console.log(Object.is(NaN,NaN));//true

assign

let a={a:'zhang'};
let b={b:'huan'};
let c={c:'ok'};
let obj=Object.assign(a,b,c);
console.log(obj);

你可能感兴趣的:(es6对象)