Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/418.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript IIFEs和命名约定_Javascript_Angularjs_Iife - Fatal编程技术网

Javascript IIFEs和命名约定

Javascript IIFEs和命名约定,javascript,angularjs,iife,Javascript,Angularjs,Iife,也许我遗漏了一些特定于angular或javascript的要求,但有人能解释一下CarWashService在下面两次定义是否有技术上的原因吗 (function() { angular.module("cw.services") .factory("CarWashService", ['$sce', '$rootScope', function ($sce, $rootScope) { var CarWashService; return new

也许我遗漏了一些特定于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);

可能让我感到不快的是,在分配洗车服务的同一行上呼叫
return new
。对于javascript大师来说,在IILife中使用除CarWashService之外的其他名称是否有意义,如果没有其他名称的话,为了可读性?或者这是做IIFEs时可以接受的模式吗?

不管是谁写的,只是让它变得不必要的复杂,仅仅声明
CarWashService
绝对没有好处,因为他们没有利用他们创建的附加闭包。即使他们确实需要关闭私有国家,他们也有一个来自外部的功能


作为旁注,这也不适用于角度。如果您真的想要一个工厂,这可能应该返回构造函数,而不是它的实例。这看起来应该声明为服务。

这看起来太复杂了,仅此而已。