【发布时间】:2011-09-07 03:37:34
【问题描述】:
我正在使用 node.js 的 util.inspect 调用将 JavaScript 关联数组转储到日志中。所讨论的关联数组包括作为函数的成员属性。一个例子是:
var pendingscreen = {};
pendingscreen['timeoutfunction'] = function(){ sendmsg(); };
pendingscreen['timeout'] = setTimeout(pendingscreen['timeoutfunction'], 1000);
console.log(util.inspect(pendingscreen));
当我运行这个时,我得到这个错误:
TypeError: Function.prototype.toString is not generic
at Client.toString (native)
at String.STRING_ADD_LEFT (native)
at isRegExp (util.js:287:14)
at format (util.js:184:11)
at util.js:216:19
at Array.map (native)
at format (util.js:193:23)
at util.js:216:19
at Array.map (native)
at format (util.js:193:23)
有没有办法检查关联数组的成员,其中一些成员可能是函数?
【问题讨论】:
-
您能否向我确认这不是由您的 sendmsg() 函数中的某些问题引起的问题?只需执行“pendingscreen['timeoutfunction'] = function(){};”。
-
不是:我之前将其更改为匿名函数,但它仍然崩溃。我放弃了,只是重组了我的代码,所以我不需要使用
util.inspect。
标签: javascript node.js associative-array