Created
September 6, 2017 13:52
-
-
Save doug2k1/e682de670faf8bd89132c15695863835 to your computer and use it in GitHub Desktop.
'this' no JavaScript: new - 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
// As linhas comentadas mostram o que o 'new' faz pra gente | |
const Player = function (name) { | |
// const this = {} | |
this.name = name | |
this.hp = 1000 | |
this.mp = 0 | |
// return this | |
} | |
// Função chamada com 'new', portanto o 'this' será | |
// um objeto novo. | |
const cloud = new Player('Cloud') | |
console.log(cloud.name, cloud.hp, cloud.mp) // Cloud 1000 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment