azcvcza / Profile

Profile
0 stars 0 forks source link

190726-JavaScript-《classes and arrow functoin》 #2

Open azcvcza opened 5 years ago

azcvcza commented 5 years ago

GogOgo

azcvcza commented 5 years ago
let outerThis, tfeThis, afeThis;
let obj = {
  outer() {
    outerThis = this;

    traditionalFE = function() {tfeThis = this};
    traditionalFE();

    arrowFE = () => afeThis = this;
    arrowFE();
  }
}
obj.outer();
azcvcza commented 5 years ago

简单的说,outerThis的形式,类似于, var that = this; 因此绑定的是outer()这块的空间。 而traditionalFE绑定的是window afeThis则也是绑的outer();

outerThis; // obj tfeThis; // global afeThis; // obj outerThis === afeThis; // true