ES6-对象赋值,key值得构建,is()方法对比对象,assign()合并对象
ES6对象赋值:
// es5 let name = "ananiah"; let skill ='web'; let obj = {name:name,skill:skill}; console.log(obj) // es6 用变量形式赋值 let name = "ananiah"; let skill ='web'; let obj = {name,skill}; console.log(obj)
key值构建
// es6-key值的构建 let key = "skill"; var obj ={ [key]:'web' } console.log(obj)
es5自定义对象方法
//自定义对象的方法(es5) let objobj = { add:function(a,b){ return a+b; } } console.log(objobj.add(2,3)) //5
is() 比较两个对象
//is() 用来比较两个对象 let obja = {name:'annaiah'}; let objb = {name:'annaiah'}; console.log(obja.name===objb.name) //true es5方法 console.log(Object.is(obja.name,objb.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 合并对象
//assign 合并对象 let a = {a:'annaiah'}; let b = {b:'大诶啊'}; let c = {c:'web'}; let d = Object.assign(a,b,c); console.log(d)