javascript - Is there a difference between declare "use strict" on a global anonymous function or inside the controller? in AngularJs -


given 2 options:

1

(function(){  "use strict"; angular.module('someapp.controllers', [])  .controller("ctrl1", ['$scope', function($scope) {           ....  }])  .controller("ctrl2", ['$scope', function($scope) {           ....  }])   .controller("ctrl3", ['$scope', function($scope) {           ....  }]); })(); 

2

(function(){  angular.module('someapp.controllers', [])  .controller("ctrl1", ['$scope', function($scope) {         "use strict";          ....  }])  .controller("ctrl2", ['$scope', function($scope) {         "use strict";          ....  }])  .controller("ctrl3", ['$scope', function($scope) {         "use strict";          ....  }]); })(); 

is there difference between two? 1 of recommended or considered "better practice" within angular? why?

is there difference between two?

well, in first one, whole iife runs in strict mode not each of controllers.
doesn't matter long not using this, access few global variables , properties , call functions, in case making mistake in iife might helpful.

and of course it's less write greater benefit, there's no reason not use it.


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -