JavaScriptCheatSheet icon indicating copy to clipboard operation
JavaScriptCheatSheet copied to clipboard

`this` is not tied to the function

Open gezeta-id opened this issue 4 years ago • 2 comments

There's a section called:

The this of Parent Scopes

And it starts by saying:

Since each function has its own this binding, whose value depends on the way it is called, you cannot refer to the this of the wrapping scope in a regular function defined with the function keyword.

This is incorrectly worded. There is no concept at all of "the this of a scope", as it's not associated to a scope. So the title is not correct. Also the explanation will be confusing to novices because it, again, relates this to some wrapping scope.

gezeta-id avatar Jan 27 '21 10:01 gezeta-id

If you have a suggested fix, I'm happy to copy-paste and put it there :-)

alhassy avatar Jan 27 '21 19:01 alhassy

The this of Global Scope .. is apt

If a variable or function is global, it can be got at from anywhere. In a browser, the global scope is the window object

The only other scope we can have is Local Scope. JavaScript scopes at a function level.

shamaayilahmed avatar Jan 28 '21 05:01 shamaayilahmed