繁体   English   中英

我如何将console.log功能与其所有属性一起使用?

[英]How can I console.log functions alongside all their properties?

我正在使用谷歌Chrome控制台。 令人沮丧的是,以下代码

var f = function () {};
f.a = 1;
console.log(f);

只会记录

function(){}

为什么不打印f的属性,例如faf.prototype 我该如何打印?

试试console.dir

console.dir(f);

console.dir列出了对象的所有已定义属性。 我想这可能就是你要找的东西。

如何在FF(Firebug)中出现

Firebug中的console.dir

它是如何出现在Chromium的控制台中的

Chromium中的console.dir

我不确定是否有关于此功能的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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM