node.js - util.inspect 默认深度应该是 20,但看起来更小
问题描述
代码
考虑以下 Node.js 代码:
const { inspect } = require('util');
const obj = { response: [ { webhooks: [ 1, 2, 3 ] } ] };
console.log(`Obj is ${obj}`);
console.log(`Obj is ${inspect(obj, { breakLength: Infinity })}`);
console.log(`Obj is ${inspect(obj, { breakLength: Infinity, depth: 20 })}`);
console.log(`Obj is ${inspect(obj, { breakLength: Infinity, depth: Infinity })}`);
给出:
Obj is [object Object]
Obj is { response: [ { webhooks: [Array] } ] }
Obj is { response: [ { webhooks: [ 1, 2, 3 ] } ] }
Obj is { response: [ { webhooks: [ 1, 2, 3 ] } ] }
问题
根据手册:
depth 指定在格式化对象时递归的次数。这对于检查大型复杂对象很有用。要使其递归到最大调用堆栈大小,请传递 Infinity 或 null。默认值:20。
据我了解,第二console.log
行应该打印与第三行相同的字符串,因为默认为depth
20。唉,它打印[Array]
而不是[ 1, 2, 3 ]
.
我的问题
为什么默认调用的行为不像depth: 20
?
解决方案
推荐阅读
- python - ModuleNotFoundError:没有名为“MySQLdb”的模块
- ruby - 重复字符串
- c++ - 模板参数推导失败和函数参数/参数不匹配
- python - 如何从 .csv 文件中提取值并将它们放入数组中?
- udp - UDP 数据报发送的正确 AT 命令序列
- opencv - OpenCV 在 minAreaRect 中使用什么算法来寻找边界框?
- amazon-web-services - 为什么 Tomcat8 的 webapps 包中的示例失败并出现“未找到”和“NullPointerException”错误?
- c# - 类为 Arg 的 Razor 页面处理程序
- java - Q : 租车计算器 | 使用哨兵值循环
- python - 使用 OPENCV 识别产品