4. Object

1. Object.is( );  //用来判断,不同等 == 与===接近。NaN作出的调整
  let obj={a:1,b:2};
  Object.is(obj,obj);//true
  Object.is(obj,{obj});//false
  Object.is({},{});//false
  Object.is('1',1);//false
  Object.is(-0,0);//false
  Object.is(NaN,NaN);//true
  Object.is(NaN,-NaN);//true

2. Object.assign()
  let obj={a:1,b:2};
  Object.assign(obj,{c:3});//obj={a:1,b:2,c:3}
  let obj1={a:1,b:2};  
  let obj2={a:'a',c:3};
  Object.assign(obj1,obj2);//obj1={a:'a',b:2,c:3}
  let obj1={a:1,b:2};
  let obj2={a:'a',c:3};
  Object.assign({},obj1,obj2);//返回新对象{a:'a',b:2,c:3}
  ///////////////////////////
  let arr=[1,2,3];
  Object.assign(arr,['a']);//arr=['a',2,3]
  let arr1=[1,2,3];
  let arr2=[,,,'a','b','c']
  Object.assign([],arr1,arr2);//返回新数组[1, 2, 3, "a", "b"]

posted @ 2018-08-30 10:09  大耳朵小虎  阅读(95)  评论(0编辑  收藏  举报