this refer to the owner object
- this in a method refers to the owner of the method
- this alone refers to the global object window
- this in a function refers to the global object window
- // in a method
- var person = {firstName: "John", lastName : "Doe",
- fullName : function() {
- return this.firstName + " " + this.lastName; // refer to person
- }
- };
-
- console.log(person.fullName());
-
- // alone
- var x = this; // refer to window
-
- console.log(x);
-
- // in a function
- function f()
- {
- return this; // refer to window
- }
-
- console.log(f());
-