为 Angular 风格指南 1.5 重新格式化

Reformatting for Angular style guide 1.5

我正在使用 Angular spyboost utility wrapper. I am trying to reformat it for this angular 1 style guide。我很难处理其中的一部分。我想我大部分都是正确的,但是 angular.forEach 函数让我失望了。我现在和现在都收到错误“Expected '{' 而不是看到 'result'。有人可以帮我吗?

 angular
    .module('myMod')
    .factory('MyService');
MyService.$inject = ['$rootScope', 'atmosphereService', 'atmosphere'];

function MyService ($rootScope, atmosphere) {
    return {
        subscribe: subscribe,
        getMessage: getMessage
    };

    function subscribe (r) {
        var responseParameterDelegateFunctions = ['onOpen', 'onClientTimeout', 'onReopen', 'onMessage', 'onClose', 'onError'];
        var delegateFunctions = responseParameterDelegateFunctions;
        var result = {};

        delegateFunctions.push('onTransportFailure');
        delegateFunctions.push('onReconnect');

        angular.forEach(r, function (value, property) {
            if (typeof value === 'function' && delegateFunctions.indexOf(property) >= 0) {
                if (responseParameterDelegateFunctions.indexOf(property) >= 0)
                    **result[property] = function (response) {**
                        $rootScope.$apply(function () {
                            r[property](response);
                        });
                    };
                else if (property === 'onTransportFailure')
                    result.onTransportFailure = function (errorMsg, request) {
                        $rootScope.$apply(function () {
                            r.onTransportFailure(errorMsg, request);
                        });
                    };
                else if (property === 'onReconnect')
                    result.onReconnect = function (request, response) {
                        $rootScope.$apply(function () {
                            r.onReconnect(request, response);
                        });
                    };
            } else
                result[property] = r[property];
        });

        function getMessage () {
            var vm = this;
            var request = {
                url: '/chat',
                contentType: 'application/json',
                transport: 'websocket',
                reconnectInterval: 5000,
                enableXDR: true,
                timeout: 60000
            };

            request.onMessage(response); {
                vm.$apply (function () {
                    vm.model.message = atmosphere.util.parseJSON(response.responseBody);
                });
            }
        }
        return atmosphere.subscribe(result);
    }

}

})(window.angular);
if (responseParameterDelegateFunctions.indexOf(property) >= 0)

缺少花括号?

if (responseParameterDelegateFunctions.indexOf(property) >= 0) {
    result[property] = function (response) {
           $rootScope.$apply(function () {
                    r[property](response);
                });
           };
}
else if (property === 'onTransportFailure') {
     result.onTransportFailure = function (errorMsg, request) {
         $rootScope.$apply(function () {
             r.onTransportFailure(errorMsg, request);
          });
      };
}
else if (property === 'onReconnect') {
     result.onReconnect = function (request, response) {
         $rootScope.$apply(function () {
              r.onReconnect(request, response);
         });
     };
}