Created
March 20, 2017 17:37
-
-
Save topicus/b414e4d0dd9036a4e5423b8ccea150c5 to your computer and use it in GitHub Desktop.
How arrow functions works with this
This file contains hidden or 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
function Animal() { | |
// this points to animal | |
document.addEventListener('click', (e) => { | |
// Unlike regular functions arrow functions takes this from the | |
// outer context so it points to animal as well. | |
console.log(this) | |
}); | |
} | |
let animal = new Animal(); | |
// In fact you can't change |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment