Can anyone advise me how to create a method call using a string and without using eval
? Please note that methodCall
cannot be hard-coded and has to be dynamic. methodCall
will be created dynamically.
In the following example this
refers to a Backbone view, e.g.
var amount = this.model.get('amount');
var $amount = this.$el.find('.amount');
var methodCall = 'this.parentController.parentController.addBinding';
//then need to call the method with args
methodCall('amount',$amount);
I first thought this would work:
this['controller']['parentController']['view']['addBinding'](amount, $amount);
However I came to realise that this would not be dynamic either. Does anyone have a solution?