contexting in javascript code example
Example: context javascript
console.log(this);
// Window {0: Window, window: Window, self: Window, document: document, name: "", location: Location, …}
class MyClass {
constructor(x, y){
this.x = x;
this.y = y;
this.sum = x + y;
}
printThis(){
console.log(this);
}
}
myClass = new MyClass(3, 4);
myClass.printThis();
// MyClass {x: 3, y: 4, sum: 7}