1// this = current execution context (window in browser, global in nodejs)
2console.log(this) // window object
3
4function foo () {
5 console.log(this); // object calling this function
6}
7
8foo(); // undefined
9
10o={ foo }
11o.foo(); // 'o' object logged
1The JavaScript this keyword refers to the object it belongs to.
2It has different values depending on where it is used: In a method,
3this refers to the owner object. Alone, this refers to the global
4object.
1var wF = {
2 w : 560,
3 h : function() { return (312 - 42) / (560 / this.w) + 42; }
4};
5
6alert(wF.h())
7
1// Im Webbrowser ist das window Objekt das globale Objekt:
2console.log(this === window); // true
3
4a = 37;
5console.log(window.a); // 37
6
7this.b = "MDN";
8console.log(window.b); // "MDN"
9console.log(b); // "MDN"
10
1Go to This link :- https://itnext.io/the-this-keyword-in-javascript-demystified-c389c92de26d