Skip to content

Instantly share code, notes, and snippets.

@topicus
Created March 20, 2017 17:37
Show Gist options
  • Save topicus/b414e4d0dd9036a4e5423b8ccea150c5 to your computer and use it in GitHub Desktop.
Save topicus/b414e4d0dd9036a4e5423b8ccea150c5 to your computer and use it in GitHub Desktop.
How arrow functions works with this
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