原型中的函数列表

Mic*_*nor 5 javascript node.js

我希望能够获得不同 JavaScript 对象上的函数列表,但特别是 String 和其他原语。我以为我能够以某种方式使用 String.prototype 并神奇地获得原型中的函数列表,但没有骰子。有任何想法吗?

我也尝试使用下划线。例如

_.functions("somestring");
Run Code Online (Sandbox Code Playgroud)

...不适合我。

ade*_*neo 4

您可以使用getOwnPropertyNames来实现此目的,它返回所有属性的数组,无论是否可枚举

Object.getOwnPropertyNames(String.prototype)
Run Code Online (Sandbox Code Playgroud)

小提琴

如果您只需要功能(length我认为这只会排除?)您可以过滤

var fns = Object.getOwnPropertyNames(String.prototype).filter(function(itm) {
    return typeof String.prototype[itm] == 'function';
});
Run Code Online (Sandbox Code Playgroud)

小提琴