Skip to content

Instantly share code, notes, and snippets.

@dekisr
Created February 9, 2019 11:54
Show Gist options
  • Save dekisr/3cbd305e1dd6ed60b6787b9b063013b7 to your computer and use it in GitHub Desktop.
Save dekisr/3cbd305e1dd6ed60b6787b9b063013b7 to your computer and use it in GitHub Desktop.
Exemplos para Wenderson
class Teste {
constructor() {
this.oi = 'Bom Dia'
}
// problema com o this
bomDiaUndefined() {
setTimeout(function() {
console.log(this.oi)
}, 1000)
}
// closure
bomDiaClosure() {
let what = this
setTimeout(function() {
console.log(what.oi)
}, 2000)
}
// arrow
bomDiaArrow() {
setTimeout(() => {
console.log(this.oi)
}, 3000)
}
}
const teste = new Teste()
teste.bomDiaUndefined()
teste.bomDiaClosure()
teste.bomDiaArrow()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment