mercredi 27 avril 2016

How invoke private function by name

How invoke function by name? Actually I know how invoke function by name, but I can't find needed scope. So now I have to use this["get" + widgetName] , it is works for _get_publishedBuildsWidget1 but I want make function as private.

So I want invoke by name _get_publishedBuildsWidget2 function

    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;
        };





Aucun commentaire:

Enregistrer un commentaire