Skip to content

Instantly share code, notes, and snippets.

@sergi
Created October 28, 2014 09:10
Show Gist options
  • Save sergi/3bcdf5e761c9ed2c843e to your computer and use it in GitHub Desktop.
Save sergi/3bcdf5e761c9ed2c843e to your computer and use it in GitHub Desktop.
Arrow functions scope
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