javascript - 如何在 Node.js 控制台中发现对象 API?

标签 javascript node.js

Canary 开发工具提供了一些很棒的功能,例如 console.tableconsole.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 - if true then the object's non-enumerable and symbol properties will be shown too. Defaults to false.

当您运行 console.dir(Promise, { showHidden: true }) 时,您将看到该对象的所有属性。

关于javascript - 如何在 Node.js 控制台中发现对象 API?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37144959/

相关文章:

javascript - react JS : Populating a rsuite dropdown from a json object

javascript - 等待 css_parser.getCSSFiles()

javascript - 检查 Id 元素 javascript

javascript - 使用 jQuery 进行字符串操作

javascript - 如何将一个对象内部的值数组分组到另一个对象数组

node.js - 使用 node 启动应用程序但不是 yarn 或 npm

javascript - 内容 slider 问题

javascript - 将数据从 JavaScript 对象加载到表中

javascript - Node : chaining exec commands with promises

node.js - 无法开始一个新的世博项目 |不再支持 Node.js 版本 14.0.0