Canary 开发工具提供了一些很棒的功能,例如 console.table
和 console.dir
,它们提供了有关对象上可用的各种函数和属性的详细信息。
我想知道这在 Node.js REPL 中是否可行。我尝试了一些在浏览器开发人员工具中效果很好的组合:
> console.dir(Promise)
[Function: Promise]
undefined
> console.log(Promise)
[Function: Promise]
undefined
> Promise
[Function: Promise]
> console.table(Promise)
TypeError: console.table is not a function
at repl:1:9
at REPLServer.defaultEval (repl.js:248:27)
at bound (domain.js:280:14)
at REPLServer.runBound [as eval] (domain.js:293:12)
at REPLServer.<anonymous> (repl.js:412:12)
at emitOne (events.js:82:20)
at REPLServer.emit (events.js:169:7)
at REPLServer.Interface._onLine (readline.js:210:10)
at REPLServer.Interface._line (readline.js:549:8)
at REPLServer.Interface._ttyWrite (readline.js:826:14)
如何在无需打开 MDN 或 Node.js 文档的情况下在 Node 内获取有关这些功能及更多内容的访问权限和文档?
最佳答案
Promise 的所有属性都是不可枚举的,因此默认情况下对 Node 的日志记录是隐藏的。您可以使用 showHidden
option of Node's console.dir
向他们展示:
showHidden
- iftrue
then the object's non-enumerable and symbol properties will be shown too. Defaults tofalse
.
当您运行 console.dir(Promise, { showHidden: true })
时,您将看到该对象的所有属性。
关于javascript - 如何在 Node.js 控制台中发现对象 API?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37144959/