Created
October 28, 2014 09:10
-
-
Save sergi/3bcdf5e761c9ed2c843e to your computer and use it in GitHub Desktop.
Arrow functions scope
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
var o = { | |
traditionalFunc: function () { | |
// Normal function, bound as expected | |
console.log('traditionalFunc this === o?', this === o); | |
}, | |
arrowFunc: () => { | |
// Arrow function, bound to scope where it's created | |
console.log('arrowFunc this === o?', this === o); | |
console.log('arrowFunc this === window?', this === window); | |
} | |
}; | |
o.traditionalFunc(); | |
// traditionalFunc this === o? true | |
o.arrowFunc(); | |
// arrowFunc this === o? false | |
// arrowFunc this === window? true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment