Created
February 9, 2019 11:54
-
-
Save dekisr/3cbd305e1dd6ed60b6787b9b063013b7 to your computer and use it in GitHub Desktop.
Exemplos para Wenderson
This file contains 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
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