Created
September 6, 2017 13:56
-
-
Save doug2k1/81f818962553eea5141d156b30f3fb3b to your computer and use it in GitHub Desktop.
'this' no JavaScript: arrow function - https://blog.dmatoso.com/javascript-this-71dd763aad52
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 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