[英]How to print only the `this` object's name , and not it's contents in javascript?
考慮一下功能:
function foo() { console.log(this); } foo();
如何僅打印this
對象的名稱(窗口或全局...等),而不打印其內容?
您可以使用obj.constructor.name
在js中打印對象名稱。
function foo() { console.log(this.constructor.name) } foo()
將打印Window
您可以使用this.constructor.name
:
function foo() { console.log(this.constructor.name); } foo();
通過構造函數名稱。 console.log(this.constructor.name)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.