this Keyword

The 'this' keyword is a variable that is automatically set for you when a function is invoked.
Exactly what this value is depends on how the function is invoked.


This Owner is the Window

var a = function() { 
   alert(this);
}
a(); // Object Window


This Owner is the Object

var obj = { 
   property1 : "text",
   method1 : function() {
      alert(this.property1);
   }
}
obj.method1(); // text




© 2020 Better Solutions Limited. All Rights Reserved. © 2020 Better Solutions Limited TopPrevNext