Skip to content

Instantly share code, notes, and snippets.

@doug2k1
Created September 6, 2017 13:56
Show Gist options
  • Save doug2k1/81f818962553eea5141d156b30f3fb3b to your computer and use it in GitHub Desktop.
Save doug2k1/81f818962553eea5141d156b30f3fb3b to your computer and use it in GitHub Desktop.
'this' no JavaScript: arrow function - https://blog.dmatoso.com/javascript-this-71dd763aad52
const player = {
name: 'Cloud',
weapon: 'Fusion Sword',
sayNameAndAttack () {
console.log(this.name)
// Uma 'arrow function'!
// O 'this' dentro dela vai ser o mesmo que aqui fora
window.setTimeout(() => {
console.log(`${this.name} ataca com a ${this.weapon}`)
}, 1000)
}
}
player.sayNameAndAttack()
// Cloud
// Cloud ataca com a Fusion Sword
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment