How Can We Help?
In an Object
If it is used within a function in an object, “this” refers to the object that “owns” the function it is called from.
Not in an Object
If it is used alone or in a function defined in the global scope – i.e. not within an object, “this” refers to the Global object (the Window object in a browser).
However, “this” in a nested function within a function owned by an object does not refer to the owner object, but the Global object.
Apply/Call
You can make “this” refer to any object if you use the “apply” or “call” method:
Comments are closed.