I put all my code in NS, similar to how jQuery is structured. I have a few variables global to NS, that I would like to enclose and then make accessible like this -> Global.variable_name.
Below is the way I did it. Is this good practice? Is there a better way to do this where I do not have to call var Global = new GlobalMaker()
I use all capitals for global CONSTANTS.
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 }
new> You can just build an object literal.var Global = {...properties...};tag_array: [],, and no, the properties need values. You can usenullas a substitute.