Created
October 6, 2021 11:31
-
-
Save ErickWendel/1a0b8b5a701e7e5159387e4832017e4f to your computer and use it in GitHub Desktop.
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
| class Context { | |
| static printSomething() { console.log('context working',) } | |
| static initializeTerminalWithClosure() { return () => this.printSomething() } | |
| static initializeTerminal() { this.printSomething() } | |
| } | |
| setTimeout(Context.initializeTerminal) | |
| // erro pois "this" é do contexto de setTimeout | |
| setTimeout(Context.initializeTerminal.bind(Context)) | |
| // com bind você fala o que é para ter no "this" da função | |
| setTimeout(Context.initializeTerminalWithClosure()) | |
| // com closure o "this" é "herdado" da função anterior |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment