What is “this” in JavaScript?

How Can We Help?

< Back

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.

This is the legacy version of the XMPro Documentation site. For the latest XMPro documentation, please visit documentation.xmpro.com

X