javascript 或 nodejs 中 Python 的 help() 的等价物

Equivalent of Python's help() in javascript or nodejs

当我想知道python中函数的参数个数和参数类型时,我只需使用函数help() 来获取它们。但是在 javascript 或 nodejs 中,很难知道函数的参数类型和参数个数。在Javascript中是否有类似于Python的帮助的功能,或者是否有任何其他方式获取该信息?

现代 IDE 可以根据它们包含的类型定义(用 TypeScript 编写)为您呈现 ECMAScript API 的这些信息。除此之外,您必须查看函数实现(或切换到 TypeScript ;))。

JavaScript 是动态类型的,所以很难分辨类型。对于参数的数量,您可以尝试 Function.length with some caveats. Some hints about argument type of not built-in functions can provide Function.prototype.toString(),使用完整或截断的输出。例如:

> fs.read.length
6
> fs.read.toString().replace(/\{.+/s, '')
'function read(fd, buffer, offset, length, position, callback) '

或者您可以将 TypeScript 与 IDE)

一起使用