Skip to content

Instantly share code, notes, and snippets.

@liammclennan
Created April 7, 2011 04:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liammclennan/907018 to your computer and use it in GitHub Desktop.
Save liammclennan/907018 to your computer and use it in GitHub Desktop.
Inspecting a JavaScript object
Object.prototype._methods = function() {
var methods = [];
for (m in this) {
if (typeof this[m] === 'function' && m !== '_methods' && m !== '_properties') {
methods.push(m);
}
}
return methods;
}
Object.prototype._properties = function() {
var properties = [];
for (p in this) {
if (typeof this[p] !== 'function') {
properties.push(p + "=" + this[p]);
}
}
return properties;
}
console.log({b: function() {}}._methods());
console.log({a: 1, c: "dfa"}._properties());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment