Skip to content

Instantly share code, notes, and snippets.

@thet
Created December 15, 2020 11:11
Show Gist options
  • Save thet/07145dfbfec9bf6c1213b7fc9f963450 to your computer and use it in GitHub Desktop.
Save thet/07145dfbfec9bf6c1213b7fc9f963450 to your computer and use it in GitHub Desktop.
The this context and inner functions
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