Answers for "context javascript"

3

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}
Posted by: Guest on March-18-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language