Created
May 1, 2016 19:28
-
-
Save JoeyBurzynski/e9fd03793d7bc02f4b7d23871ea129ea to your computer and use it in GitHub Desktop.
JavaScript: Get All Methods on an 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
// Get all methods on an object | |
function getOwnMethods(obj) { var props = Object.getOwnPropertyNames(obj); return props.filter(function(prop) { return obj[prop] && obj[prop].constructor && obj[prop].call && obj[prop].apply; }); } | |
// Example Object | |
var Module = { str: "a string", array: [1, 2, 3, 4], alpha: function() { return this; }, beta: function() { return this; }, delta: function() { return this; } }; console.log( getOwnMethods(Module) ); // > ["delta", "alpha", "beta"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment