Get functions (methods) of a class [duplicate]

The members of a class are not enumerable. To get them, you have to use Object.getOwnPropertyNames:

var propertyNames = Object.getOwnPropertyNames(Object.getPrototypeOf(foo));
// or
var propertyNames = Object.getOwnPropertyNames(Foo.prototype);

Of course this won’t get inherited methods. There is no method that can give you all of them. You’d have to traverse the prototype chain and get the properties for each prototype individually.

Leave a Comment