Created
April 7, 2011 04:05
-
-
Save liammclennan/907018 to your computer and use it in GitHub Desktop.
Inspecting a JavaScript object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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