我将所有代码都放在 NS 中,类似于 jQuery 的结构。我有一些 NS 全局变量,我想将它们包含在内,然后像这样访问 -> Global.variable_name
。
下面是我的做法。这是好习惯吗?有没有更好的方法可以做到这一点,我不必打电话var Global = new GlobalMaker()
我将所有大写字母用于全局常量。
var NS = ( function ( window, undefined ) { /* all my code is here */ } )( )
/** (including this code)
*GlobalMaker
*/
var GlobalMaker = function()
{
this.tag_array = [];
this.current_tag;
this.validate_input_on;
this.JSON_ON = 1; // selector between JSON and LON
this.GATEWAY = 'class.ControlEntry.php'; // for Ajax calls
this.PICTURES = '../pictures/'; // for composing tweets
this.PASS = 0;
this.FAIL = 1;
this.NOTDEFINED = 2;
};
var Global = new GlobalMaker();
/**
*Global
*/
var Global =
{
tag_array: [],
current_tag: 0,
validate_input_on: 0,
JSON_ON: 1,
GATEWAY: 'class.ControlEntry.php',
PICTURES: '../pictures/',
PASS: 0,
FAIL: 1,
NOTDEFINED: 2
}