[英]How can I console.log functions alongside all their properties?
我正在使用谷歌Chrome控制台。 令人沮喪的是,以下代碼
var f = function () {};
f.a = 1;
console.log(f);
只會記錄
function(){}
為什么不打印f
的屬性,例如fa
和f.prototype
? 我該如何打印?
試試console.dir
。
console.dir(f);
console.dir
列出了對象的所有已定義屬性。 我想這可能就是你要找的東西。
如何在FF(Firebug)中出現
它是如何出現在Chromium的控制台中的
我不確定是否有關於此功能的Chrome文檔,但console
對象上有Firebug文檔 。
因為函數不是對象。
如果你這樣做:
var f = function () {};
var my_instance = new f(); // aha!
my_instance.a = 1;
console.log(my_instance);
你應該得到你期望的。
函數可以是類,但絕不是對象。 使用 new
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.