Skip to content

Instantly share code, notes, and snippets.

@doug2k1
Created September 6, 2017 13:53
Show Gist options
  • Save doug2k1/a51107da05b0e02ef3c09d1022f16820 to your computer and use it in GitHub Desktop.
Save doug2k1/a51107da05b0e02ef3c09d1022f16820 to your computer and use it in GitHub Desktop.
'this' no JavaScript: new class - https://blog.dmatoso.com/javascript-this-71dd763aad52
// 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