View Full Version : Array of user-defined methods
Hi there,
Any ideas how i get an array (or any other structure) of all user-defined methods in a node?
Thanks,
Naso.
Do you mean programmatically? Or are you just trying to inspect an object? The debugger can inspect any object. By default it does not list methods or inherited properties. If you are inspecting an object `x` and you want to see the methods of that object, you would need to inspect `x.constructor.prototype`.
If you want to get out the methods programmatically, you could do something like:
var methods = {};
for (var prop in x) {
var val = x[prop];
if (val instanceof Function) {
methods[prop] = val;
}
}
If you don't want inherited methods, change the `if` to:
if (val instanceof Function && x.constructor.prototype.hasOwnProperty(prop)) {
Yes, I meant programmatically and your example is exactly what i needed.
Thanks heaps!
Naso.
vBulletin® v3.8.4, Copyright ©2000-2012, Jelsoft Enterprises Ltd.