In my controller, I have the following ref and one function that I call after clicking a button. Is it possible to construct a ref method and then call it? I just want in a single function to handle many cases and I want to avoid if statements (as it is required in the project. It is supposed to be generic)
The type will come as a parameter to the function.
refs : [{
ref : 'saleForm',
selector : 'sale saleform'
}],
init: function () {
this.control({
'salesview #mybutton':{
click : this.onSaleClick
}
});
},
onSaleClick : function(){
//this.getSaleForm().show();//works
var type = "Sale";
var method = "get"+type+"Form()";
this.window = window;
this.window[method]().show();
}
this.getSaleForm().show()works, what's wrong with doingvar method = "get" + type + "Form"; this[method]().show();? You don't want the parens in the method name because you're invoking it after you look it up, and I don't think it'll be a global method, as it's locally scoped to your class, so you don't want to usewindow.typeis a string variable in both your provided code and Lorenz Meyer's answer... unlesstypeis some special reserved variable you have, but it shouldn't be if you're local scoping it.