Hosting Solutions
mobile_logo Table of Contents
seal_frontseal_back

this

The this operator is used to refer to an object in its own local scope. An object/element/class can refer to itself as 'this' locally.

Examples

Establish local properties and methods in a custom class. function Class1(){ this.property1; this.method1 = function(){ alert( this.property1 ); } } var obj = new Class1(); obj.property1 = "Hi"; obj.method1(); Pass the calling object/element reference to a function. <script> function doIt( elem ){ alert( elem.id ); } </script> <button id="btn1" onclick="doIt( this )">Click me 1</button> <button id="btn2" onclick="doIt( this )">Click me 2</button>

JavaScript

Operators

deleteinstanceofnewthistypeofternaryvoid