Skip to content

Instantly share code, notes, and snippets.

@wonglok
Last active August 29, 2015 14:00
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 wonglok/11103878 to your computer and use it in GitHub Desktop.
Save wonglok/11103878 to your computer and use it in GitHub Desktop.
get methods keys from obj
function getMethods(obj)
{
var bucket = [];
var key
for(key in obj) {
if(typeof obj[key] === "function") {
bucket.push(key)
}
}
return bucket;
}
getMethods({ a: function(){ console.log('a method'); } });
//---------
var buttonView = {
label : 'underscore',
onClick: function(){ alert('clicked: ' + this.label); },
onHover: function(){ console.log('hovering: ' + this.label); }
};
_.bindAll(buttonView, 'onClick', 'onHover');
// When the button is clicked, this.label will have the correct value.
jQuery('#underscore_button').bind('click', buttonView.onClick);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment