Problem
there is a other way to write in JS the switch statement ,
This code is working 🙂
_update: function(oHtml, oConfig) {
var _this = this;
var oParent;
if (oConfig.attributes != null) {
oConfig.attributes.forEach(function(oAttr) {
//debugger;
oParent = oHtml.find("#" + oAttr.id);
switch (oAttr.action) {
case 'upd':
_this._updateAttr(oParent, oAttr);
break;
case 'new':
_this._insertAttr(oParent, oAttr);
break;
case 'del':
_this._removeAttr(oParent, oAttr);
}
});
return oHtml;
}
},
We are using require JS
Solution
You can try something like this, saving the names of the functions in a variable, and then accessing the variable with the name of the action, you can also save the reference of the functions of the variable in the properties and you would not have to use ‘this’
_update: function(oHtml, oConfig) {
var _this = this;
var oParent;
var actionsToExecute = {
upd : '_updateAttr',
new : '_insertAttr',
del : '_removeAttr'
}
if (oConfig.attributes != null) {
oConfig.attributes.forEach(function(oAttr) {
//debugger;
oParent = oHtml.find("#" + oAttr.id);
_this[actionsToExecute[oAttr.action]](oParent,oAttr)
});
return oHtml;
}
},