Skip to content

Instantly share code, notes, and snippets.

@JoeyBurzynski
Created May 1, 2016 19:28
Show Gist options
  • Save JoeyBurzynski/e9fd03793d7bc02f4b7d23871ea129ea to your computer and use it in GitHub Desktop.
Save JoeyBurzynski/e9fd03793d7bc02f4b7d23871ea129ea to your computer and use it in GitHub Desktop.
JavaScript: Get All Methods on an Object
// 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