且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在使用strict mode pragma时声明全局变量

更新时间:2023-12-05 23:38:16

IMO替代3是***的。但它假设窗口表示全局范围 - 对于浏览器而言是这样,但对于其他JS环境(命令行,Node.js等)则不然。

IMO alternative 3 is best. But it assumes that window represents the global scope - which is true for the browser but not for other JS environments (command line, Node.js, etc.).

以下内容将全面运作:

(function(globals){
  "use strict";
  globals.GLOB = {};
}(this));