• RSS Unknown Feed

    • An error has occurred; the feed is probably down. Try again later.
  • Meta

JavaScript this Keyword

The ‘this’ keyword is indispensable in JavaScript object-oriented programming. When used in a JavaScript constructor function, ‘this’ refers to the object. Through the ‘this’ keyword, properties and methods can be assigned object, also known as a class. For example:

function Square(intSideLength)
{
this.sideLength = intSideLength;
}

In the preceding example the ‘this’ keyword is used to assign the variable ‘sideLength’ as a property of the Square class.

The ‘this’ keyword is also frequently passed as a parameter on JavaScript events, such as when a checkbox is clicked. In such an instance, ‘this’ refers to the current object, the checkbox.

Leave a comment