Skip to content

Instantly share code, notes, and snippets.

@iandundas
Created May 20, 2013 04:39
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 iandundas/5610453 to your computer and use it in GitHub Desktop.
Save iandundas/5610453 to your computer and use it in GitHub Desktop.
Inspect Javascript Object
/* inspect a javascript object
http://codeinthehole.com/writing/inspecting-javascript-objects/
Usage: Inspect.properties(variable);
Inspect.methods(variable);
*/
var Inspect = {
TYPE_FUNCTION: 'function',
// Returns an array of (the names of) all methods
methods: function(obj) {
var testObj = obj || self;
var methods = [];
for (prop in testObj) {
if (typeof testObj[prop] == Inspect.TYPE_FUNCTION && typeof Inspect[prop] != Inspect.TYPE_FUNCTION) {
methods.push(prop);
}
}
return methods;
},
// Returns an array of (the names of) all properties
properties: function(obj) {
var testObj = obj || self;
var properties = [];
for (prop in testObj) {
if (typeof testObj[prop] != Inspect.TYPE_FUNCTION && typeof Inspect[prop] != Inspect.TYPE_FUNCTION) {
properties.push(prop);
}
}
return properties;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment