Last active
August 29, 2015 14:00
-
-
Save wonglok/11103878 to your computer and use it in GitHub Desktop.
get methods keys from obj
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 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