Skip to content

Instantly share code, notes, and snippets.

@NyaGarcia
Last active March 6, 2021 17:59
Show Gist options
  • Save NyaGarcia/f5bb473f03b4eb014c23324e74625034 to your computer and use it in GitHub Desktop.
Save NyaGarcia/f5bb473f03b4eb014c23324e74625034 to your computer and use it in GitHub Desktop.
Example showing scope in arrow function object methods
const pokemon = {
experience: 0,
fight: () => {
this.experience += Math.floor(Math.random() * 10) + 1;
}
};
pokemon.fight();
console.log(pokemon.experience);
// Output: 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment