jQuery の構造と同様に、すべてのコードを NS に配置しました。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
}