我已经开始学习AngularJS并同时通过一些代码样本去我碰到下面传来:AngularJS和IIFE
(function(app) {
'use strict';
app.directive('sideBar', sideBar);
function sideBar() {
return {
restrict: 'E',
replace: true,
templateUrl: '/scripts/spa/layout/mypage.html'
}
}
})(angular.module('common.ui'));
上面的代码创建使用IIFE自定义指令。我对代码的最后一行非常困惑。它传递一个名为common.ui的模块。有人能解释一下,这种传递参数的方式是如何工作的,以及如何以不同的方式重写这些参数?
'angular.module( 'common.ui')'变成由'app'引用。请参阅http://stackoverflow.com/questions/8228281/what-is-the-function-construct-in-javascript。 – Jasen