let name=‘jin‘; let skill=‘web‘; //ES6允许我们用变量的形式赋值 let obj={name,skill}; console.log(obj); //key值的构建 let key="skill"; var obj1={ [key]:‘web‘ } console.log(obj1); //es5就有的自定义对象方法 let obj2={ add:function(a,b){ return a+b; } } console.log(obj2.add(1,2)); //is() let obj3={name:‘tanhua‘}; let obj4={name:‘tanhua‘}; console.log(obj3.name===obj4.name); // 下面是es6的方法 console.log(Object.is(obj3.name,obj4.name)); console.log(+0===-0); // ===同值相等,is严格相等 console.log(NaN===NaN); //对象比较 console.log(Object.is(+0,-0)); console.log(Object.is(NaN,NaN)); //assign合并对象 let a={a:‘tanhua‘}; let b={b:‘xianhua‘}; let c={c:‘web‘}; let d=Object.assign(a,b,c); console.log(d);
原文地址:https://www.cnblogs.com/NeryXJ/p/9648212.html
时间: 2024-11-02 15:38:50