[英]util.inspect behaves differently on different node versions
code: 码:
var util = require('util')
var body = '{doc}'
try{
body = JSON.parse(body)
}catch(err){
console.log(util.inspect(err))
}
The same code running on different versions giving different results 在不同版本上运行的相同代码给出不同的结果
node 6.xx: (inspect is not working) 节点6.xx :(检查不起作用)
SyntaxError: Unexpected token i in JSON at position 1
at Object.parse (native)
on node 0.xx: 在节点0.xx上:
[SyntaxError: Unexpected token i]
PS: I have used depth null, still am getting same results on nodev6 PS:我使用深度为null,但在nodev6上仍得到相同的结果
It's not that it's not working, it's just that the util.inspect()
implementation changed between the major node versions. 并不是说它没有工作,而是在主要节点版本之间更改了util.inspect()
实现。 Typically it's changes like this that only happen in a new major version, so it probably changed with a new major version (eg 4.0.0, 5.0.0, etc.). 通常,仅在新的主要版本中会发生这样的更改,因此它可能会在新的主要版本(例如4.0.0、5.0.0等)中发生更改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.