JavaScript中全局变量的命名和格式化标准是什么?
例如:
var global_var // ?
var _global_var // ?
var GLOBAL_VAR // ?
var _GLOBAL_VAR // ?
...
Run Code Online (Sandbox Code Playgroud)
注意:我不是在谈论常量,只是简单地说具有全局范围的变量.
对于我的Web应用程序,我在JavaScript中创建一个名称空间,如下所示:
var com = {example: {}};
com.example.func1 = function(args) { ... }
com.example.func2 = function(args) { ... }
com.example.func3 = function(args) { ... }
Run Code Online (Sandbox Code Playgroud)
我也想创建"私有"(我知道这在JS中不存在)命名空间变量,但我不确定什么是最好的设计模式.
可不可能是:
com.example._var1 = null;
Run Code Online (Sandbox Code Playgroud)
或者设计模式是否是别的?