Javascript 使用JS闭包/煎锅构造角度代码-将应用程序注入为;这是—我该不该这么做?
这是一个好的做法还是一个坏的做法,以这种方式构造代码并注入依赖项,如下所示? 我喜欢在闭包中分离我的所有代码,以便按照下面的方式构造它们——据我所知,这是一种很好的做法,因为在闭包中而不是在根范围中使用严格模式不会阻止其他可能根本不使用它的库。如果那也是错的,请纠正我 给出我的方法的以下示例代码:Javascript 使用JS闭包/煎锅构造角度代码-将应用程序注入为;这是—我该不该这么做?,javascript,angularjs,dependency-injection,code-structure,Javascript,Angularjs,Dependency Injection,Code Structure,这是一个好的做法还是一个坏的做法,以这种方式构造代码并注入依赖项,如下所示? 我喜欢在闭包中分离我的所有代码,以便按照下面的方式构造它们——据我所知,这是一种很好的做法,因为在闭包中而不是在根范围中使用严格模式不会阻止其他可能根本不使用它的库。如果那也是错的,请纠正我 给出我的方法的以下示例代码: /** * @this {angular.module} * @param {jQuery} $ * @param {undefined} undefined */ (function ($,
/**
* @this {angular.module}
* @param {jQuery} $
* @param {undefined} undefined
*/
(function ($, undefined) {
'use strict';
/**
* @param {$routeProvider} $routeProvider
*/
this.config(function ($routeProvider) {
$routeProvider
.when('/', {
templateUrl: 'views/main.html',
controller: 'MainCtrl',
controllerAs: 'main'
})
.when('/about', {
templateUrl: 'views/about.html',
controller: 'AboutCtrl',
controllerAs: 'about'
})
.otherwise({
redirectTo: '/'
});
});
}).call(window.myApp = window.myApp || createApp(), jQuery);
向上投票的附带问题(我认为这是相关的,因为我将myApp注入为“this”,但请让我知道我们是否严格,这应该是一个单独的问题):如何键入提示“this”