How can I call a function by its name? I understand how to call a function by name, but I am struggling to find the necessary scope. Currently, I am using this["get" + widgetName], which works for _get_publishedBuildsWidget1 but I would like to make the function private.
My goal is to call the function _get_publishedBuildsWidget2 by its name.
function widgetGeneratorService(commonDashboardService, $filter, buildService, $state) {
var widgetGeneratorServiceFactory = {};
widgetGeneratorServiceFactory._get_publishedBuildsWidget1 = function (widget) {
widget.name = "Test";
return widget;
}
var _get_publishedBuildsWidget2 = function(widget){
widget.name = "Test";
return widget;
}
widgetGeneratorServiceFactory.getDefaultWidget = function (widgetName) {
var defaultWidget = {};
//TODO rewrite!!!
var fnGenerateWidget = this["_get_" + widgetName];
if (typeof fnGenerateWidget === 'function') {
return fnGenerateWidget(defaultWidget);
}
return defaultWidget;
}
return widgetGeneratorServiceFactory;
};