

But hang in there we are getting to the good stuff now.

So, as you can see, “this” can easily give you a headache. When you instantiate a constructor function, inside of the instance object, “this” refers to the instance object.When a function executes inside of another function ( no matter how deeply nested), “ this” refers to the object whose context within which it is executed.When a function is a method of an Object, “ this” refers to that object (unless it is manually executed in the context of a different object).When a function executes in the global context, “ this” refers to the global, or “ window” object.When a function is executed, the keyword “this” refers to the object that the function is executed in. “self”), and provides an interface to the properties and methods that are members of that object. Within an object, the keyword “ this” refers to that object (i.e.

In JavaScript, “ context” refers to an object. Sometimes the words “ scope” and “ context” are used interchangeably, which only leads to confusion because they are not the same thing. In the post: “ Understanding Scope in JavaScript,” I covered the basics of how scope works when dealing with functions. Why is the word “this” so important in JavaScript?
