Vue Js W3schools

Posted on  by admin
  • javascript by iamhanumanth on May 11 2020 Comment .
  • const person = { firstName: "John", lastName : "Doe", id : 5566, fullName : function() { return this.firstName + " " + this.lastName; }};.
  • Try it Yourself ».

In JavaScript, the this keyword refers to an object. Which object depends on how this is being invoked (used or called). The this keyword refers to different objects depending on how it is used:. Notethis is not a variable. It is a keyword. You cannot change the value of this. When used in an object method, this refers to the object. In the example on top of this page, this refers to the person object.

Because the fullName method is a method of the person object. fullName : function() { return this.firstName + " " + this.lastName;}. Try it Yourself ». When used alone, this refers to the global object. Because this is running in the global scope.

In a browser window the global object is [object Window]:. Try it Yourself ». In strict mode, when used alone, this also refers to the global object:.

Try it Yourself ».