Name

this — NN 2 IE J1 ECMA 1

Synopsis

A keyword that refers to the current object. For example, in a form element object event handler, you can pass the object as a parameter to the function:

<INPUT TYPE="text" NAME="ZIP" onChange="validate(this)">

Inside a custom object constructor, the keyword refers to the object itself, allowing you to assign values to its properties (even creating the properties at the same time):

function CD(label, num, artist) {
    this.label = label
    this.num = num
    this.artist = artist
}

Inside a function, the this keyword refers to the function object.

Example

<INPUT TYPE="text" NAME="phone" onChange="validate(this.value)">

Get Dynamic HTML: The Definitive Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.