我试图找到一种干净、简单的方法来使用命令行简单地获取 Node.js 中类的可用函数列表。
根据我之前偶然发现的网络搜索Object.getOwnPropertyNames(),但似乎这个功能不一致,否则我不明白为什么它适用于某些类但不适用于其他类。
让我们看一个例子,也许有人可以提供帮助。目前,本示例的 node -v 输出 v4.4.5。
首先,假设我想获取 Math 类的函数列表。从节点控制台,这效果很好,我得到:
[root@localhost /]# node
> Object.getOwnPropertyNames(Math)
[ 'E',
'LN10',
'LN2',
'LOG2E',
'LOG10E',
'PI',
'SQRT1_2',
'SQRT2',
'random',
'abs',
'acos',
'asin',
'atan',
'ceil',
'exp',
'floor',
'log',
'round',
'sqrt',
'atan2',
'pow',
'max',
'min',
'imul',
'sign',
'trunc',
'tanh',
'asinh',
'acosh',
'atanh',
'hypot',
'fround',
'clz32',
'cbrt',
'cos',
'sin',
'tan',
'sinh',
'cosh',
'log10',
'log2',
'log1p',
'expm1' ]
>
Run Code Online (Sandbox Code Playgroud)
凉爽的。这样可行。
现在,由于 Node.js 更多的是关于服务器端编程,让我们看看同样的事情是否适用于 Node.js 的几乎每个“hello world”类型示例中使用的公共类:http.Server
让我们尝试同样的事情:
> Object.getOwnPropertyNames(http.Server)
[ 'length', 'name', 'prototype', …Run Code Online (Sandbox Code Playgroud)