CNode

node打印对象的2种方法

分享
Ii5ting发布于12 年前最后回复11 年前4 回复23889 浏览0 收藏

法1

console.dir(response)

法2

var inspect = require('util').inspect;
console.log(inspect(response))

目前我测试是差不多的,不知道它们有啥差别,求指教

查看回复

回复 (4)

M
MiguelValentine#1·12 年前

Console.prototype.dir = function(object, options) { this._stdout.write(util.inspect(object, util._extend({ customInspect: false }, options)) + '\n'); };

Console.prototype.log = function() { this._stdout.write(util.format.apply(this, arguments) + '\n'); };

A
alsotang#3·12 年前

@MiguelValentine @i5ting 看来还是看源码的牛逼啊。。 util.inspect 还有个

showHidden - if true then the object's non-enumerable properties will be shown too. Defaults to false.

选项。 有时候会有用。

参与回复
登录后即可参与回复。登录