Last active
August 29, 2015 14:01
-
-
Save majuric/e9695ecb1fe3761707c9 to your computer and use it in GitHub Desktop.
Call a method in Backbone.js with a string as a parameter
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
var View = Backbone.View.extend({ | |
callFunc : function(funcName) { | |
// Use array notation to fetch the function definition and call it... | |
this[funcName](); | |
}, | |
foo : function() { | |
console.log('called foo'); | |
}, | |
bar : function() { | |
console.log('called bar'); | |
} | |
}); | |
var view = new View(); | |
view.callFunc('foo'); | |
>> called foo | |
view.callFunc('bar'); | |
>> called bar |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment