Is there a method or propertie to get all methods from an object? For example:
function foo() {}
foo.prototype.a = function() {}
foo.prototype.b = function() {}
foo.get_methods(); // returns ['a', 'b'];
UPDATE: Are there any method like that in Jquery?
Thank you.
You can simply loop over the prototype of a constructor and extract all methods.
In Chrome is
keys(foo.prototype)
. Returns["a", "b"]
.See: https://developer.chrome.com/devtools/docs/commandline-api#keysobject
Later edit: If you need to copy it quick (for bigger objects), do
copy(keys(foo.prototype))
and you will have it in the clipboard.You can use
console.dir(object)
to write that objects properties to the console.In modern browsers you can use
Object.getOwnPropertyNames
to get all properties (both enumerable and non-enumerable) on an object. For instance:Note that this only retrieves own-properties, so it will not return properties found elsewhere on the prototype chain. That, however, doesn't appear to be your request so I will assume this approach is sufficient.
If you would only like to see enumerable properties, you can instead use
Object.keys
. This would return the same collection, minus the non-enumerableconstructor
property.The methods can be inspected in the prototype chain of the object using the browser's developer tools (F12):
or more directly