Created
February 26, 2019 12:58
-
-
Save ktajpuri/420868d56d220f1dd2f8d01ef0091e51 to your computer and use it in GitHub Desktop.
how-this-differs-in-arrow-functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
this.myVar = "outer"; | |
var obj = { | |
myVar: "inner", | |
myFunc1: function() { | |
console.log(this.myVar); | |
}, | |
myFunc2: () => { | |
console.log(this.myVar); | |
}, | |
myFunc3: function() { | |
setTimeout(function() { | |
console.log(this.myVar); | |
}, 1000); | |
}, | |
myFunc4: function() { | |
setTimeout(() => { | |
console.log(this.myVar); | |
}, 1000); | |
} | |
}; | |
obj.myFunc1(); //inner | |
obj.myFunc2(); //outer | |
obj.myFunc3(); //outer | |
obj.myFunc4(); //inner |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment