Created
September 6, 2017 13:53
-
-
Save doug2k1/a51107da05b0e02ef3c09d1022f16820 to your computer and use it in GitHub Desktop.
'this' no JavaScript: new class - 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
// Usando 'class' o 'new' chama o construtor e faz a mesma coisa com o 'this' | |
class Player { | |
constructor (name) { | |
// const this = {} | |
this.name = name | |
this.hp = 1000 | |
this.mp = 0 | |
// return this | |
} | |
} | |
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