标签云

微信群

扫码加入我们

WeChat QR Code

I'm refactoring an old AngularJS 1.3 project. One of the things I noticed is that the person who made this started every single file of AngularJS code with:

(function () {
'use strict';

  angular.module('app').factory('Employees', ['$http', function($http) {
    // angular code removed
  }]);

})();

Does using function() 'use strict' in every single file any benefit to the code? To me it feels like a waste of 3 lines in every single file. Is there a standard / best practice for this?


I know what 'use strict' does. But I would like to find a way to only use 'use strict' once without making it global.

2018年06月19日58分50秒

See also Why is 'use strict' usually after an IIFE (rather than at the top of a script)?

2018年06月18日58分50秒

"only use 'use strict' once without making it global." is exactly what your code does, it makes the module strict.

2018年06月19日58分50秒

I would however assume that libraries which choke on being run in strict mode have other problems…

2018年06月19日58分50秒