Created
December 7, 2011 07:09
-
-
Save mdix/1441816 to your computer and use it in GitHub Desktop.
Method that returns all Methods it can find on a given 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
function getMethods(obj) { | |
var result = []; | |
var positionOfBrace = null; | |
var functionAndParams = ''; | |
var functionAsString = ''; | |
for (var id in obj) { | |
try { | |
if (typeof(obj[id]) == "function") { | |
functionAsString = obj[id].toString(); | |
positionOfBrace = functionAsString.indexOf('{'); | |
functionAndParams = functionAsString.slice(0, positionOfBrace); | |
result.push(id + ": " + functionAndParams + "{ [code] }\n"); | |
} | |
} catch (err) { | |
result.push(id + ": FAIL"); | |
} | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can just paste that in your browsers console (webdevelopper toolbar, firebug etc.) and run it by passing it a object, like: getMethods(object);