Created
December 15, 2020 11:11
-
-
Save thet/07145dfbfec9bf6c1213b7fc9f963450 to your computer and use it in GitHub Desktop.
The this context and inner functions
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
const this_test = { | |
returns_global_this() { | |
function inner() { | |
// even unbound inner function's | |
// this context is globalThis. | |
return this; | |
} | |
return inner(); | |
}, | |
returns_local_this() { | |
const inner = () => { | |
return this; | |
} | |
return inner(); | |
} | |
}; | |
this_test.returns_global_this() === globalThis; | |
this_test.returns_local_this() === this_test; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment