Last active
August 29, 2015 14:23
-
-
Save NorthDecoder/617a88df5267a6e97b34 to your computer and use it in GitHub Desktop.
Inspecting javascript objects
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
/* Reference link-> http://codeinthehole.com/writing/inspecting-javascript-objects/ | |
https://github.com/codeinthehole/js-nuggets/ | |
*/ | |
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