consider the function:
function foo() {
console.log(this);
}
foo();
How to print only the this
object's name (window or global....etc), and not it's contents?
consider the function:
function foo() {
console.log(this);
}
foo();
How to print only the this
object's name (window or global....etc), and not it's contents?
You can print an objects name in js with obj.constructor.name
.
function foo() {
console.log(this.constructor.name)
}
foo()
Will print Window
You can use this.constructor.name
:
function foo() {
console.log(this.constructor.name);
}
foo();