简体   繁体   English

Node V10 与 Node V11 中 util.format 的行为

[英]Behaviour of util.format in Node V10 vs Node V11

When I try to execute util.format with inspect as an object returning a function like当我尝试执行 util.format 并检查为 object 返回 function 时

util.format({inspect: function() { return 1; } })

Node 10 output: '1'节点 10 output:“1”

Node 11 output: '{ inspect: [Function: inspect] }'节点 11 output:“{检查:[功能:检查]}”

I couldn't find anything in the documentation in regards to using util.format having an inspect as key.我在文档中找不到任何关于使用 util.format 并将检查作为键的信息。 I am not sure why the behaviour is different.我不确定为什么行为不同。

PS: Couldn't have REPL with a older version, so I couldn't attach a reproducible version. PS:旧版本无法使用 REPL,所以我无法附上可复制的版本。 But running this code in different node version would show the logs as mentioned in the example.但是在不同的节点版本中运行此代码会显示示例中提到的日志。

Using this code in Node.js v10 gives:在 Node.js v10 中使用此代码给出:

(node:39468) [DEP0079] DeprecationWarning: Custom inspection function on Objects via.inspect() is deprecated (节点:39468)[DEP0079] DeprecationWarning:不推荐使用对象 via.inspect() 上的自定义检查 function

You should use util.inspect.custom instead of util.format See Deprecations您应该使用util.inspect.custom而不是util.format请参阅弃用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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