【发布时间】:2013-11-13 19:30:07
【问题描述】:
也许我错过了一些特定于 Angular 或 javascript 的东西,但有人可以解释一下 CarWashService 在下面定义了两次是否有技术原因?
(function() {
angular.module("cw.services")
.factory("CarWashService", ['$sce', '$rootScope', function ($sce, $rootScope) {
var CarWashService;
return new (CarWashService = (function () {
function CarWashService() {
this.results = [];
this.resultsCountText = "";
this.PageIndex = 0;
this.processing = false;
this.initialized = false;
this.showNoResults = false;
this.showResults = false;
this.noCarWashMessage = $sce.trustAsHtml($rootScope.resources.landingNoCarWashMessage);
}
return CarWashService;
})());
}]);
}).call(this);
可能让我失望的是在分配 CarWashService 的同一行上调用 return new。对于 javascript 专家来说,在 IIFE 中使用除 CarWashService 以外的其他名称是否有意义,以提高可读性?还是在进行 IIFE 时这是一种公认的模式?
【问题讨论】:
-
这看起来太复杂了,仅此而已。
标签: javascript angularjs iife