Should I 'use strict' for every single javascript function I write?

后端 未结 4 1103
逝去的感伤
逝去的感伤 2020-12-17 08:37

Should I \'use strict\' for every single javascript function I write?

What is a good practice to use strict in a large AngularJS project? Using it globally can break

4条回答
  •  醉话见心
    2020-12-17 09:12

    Short answer, yes! You don't need to include it for every function, but rather you can just add it once per JavaScript file. When you start the file, start with a closure like this:

    (function () {
      "use strict";
      // Rest of your code.
    
    })();
    

提交回复
热议问题