내가 여부 :포장 컨트롤러
(function() {
'use strict';
// Create the module and define its dependencies.
var app = angular.module('app', [
// Angular modules
'ngAnimate', // animations
'ngRoute' // routing
// Custom modules
// 3rd Party Modules
]);
// Execute bootstrapping code and any dependencies.
app.run(['$log',
function ($log) {
$log.log('we are loaded');
}]);
})();
또는
'use strict';
// Create the module and define its dependencies.
var app = angular.module('app', [
// Angular modules
'ngAnimate', // animations
'ngRoute' // routing
// Custom modules
// 3rd Party Modules
]);
// Execute bootstrapping code and any dependencies.
app.run(['$log',
function ($log) {
$log.log('we are loaded');
}]);
모두 작동하는 것 -의 차이는 무엇인가?
익명의 기능에 대해 설명해 주시면 감사하겠습니다. 하나를 사용할 때, 그리고 AngularJ에 대해 양방향으로 작성된 컨트롤러를 보는 이유는 무엇입니까?
감사합니다.
이것이 정말로 필요하다고 생각하십니까? JSHint 지침이 이와 같이 설정 되었기 때문에이 작업을 수행하는 것으로 나타났습니다. –
필수는 아니지만 코드가 없으면 정상적으로 작동하지만 좋은 이유가 있습니다. 대답에 설명했듯이 구조체를 분리하는 일에 코드를 래핑하지 않으면 페이지의 다른 코드를 간섭 할 수 있습니다. 프로젝트가 성장함에 따라 문제가 발생하기 시작합니다. JavaScript 사용 경험에 따라 이미 경험했거나 경험하지 않았을 수 있습니다. 그렇다고해서 코드 분리의 문제로 마침내 문제가 발생할 것이라는 확신을 가질 수는 있습니다. :) –
@JesseDunlap이 정말로 그 답을 못 찾았지만, Google이 후원하는 코드 학교의 "shaping up with angularJS"과정에서도 첫 번째 방법을 권장합니다. 그리고 나는 인용한다 : "당신의 자바 스크립트를 클로저로 감싸는 것은 좋은 습관이다." –