前端小白成长04--Object.is

126 阅读1分钟

Object.is()确定两个值是否相同 Ie不支持

Object.is('foo', 'foo');     // true
Object.is(window, window);   // true

Object.is('foo', 'bar');     // false
Object.is([], []);           // false

var foo = { a: 1 };
var bar = { a: 1 };
Object.is(foo, foo);         // true
Object.is(foo, bar);         // false

Object.is(null, null);       // true

// Special Cases
Object.is(0, -0);            // false
Object.is(-0, -0);           // true
Object.is(NaN, 0/0);         // true
Object.is(NaN,NaN)        //true

this指向

let obj = {
  a : 10,
  f1: ()=>{
    console.log(this);//window   this指上层对象。若无定义上层对象,则为window
  },
  f2:function(){
    console.log(this);//{a: 10, f1: ƒ, f2: ƒ, f3: ƒ}
  },
  f3(){
    console.log(this)//{a: 10, f1: ƒ, f2: ƒ, f3: ƒ}
  }
}
obj.f1();
obj.f2();
obj.f3();