Last active
March 6, 2021 17:59
-
-
Save NyaGarcia/f5bb473f03b4eb014c23324e74625034 to your computer and use it in GitHub Desktop.
Example showing scope in arrow function object methods
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
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