Revision: 30845
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at August 24, 2010 00:24 by 1man
Initial Code
var myModule = function(){ //Keep the vars outside the global namespace (global vars are evil!) var a = 122; var b = 22; return { init: function(){ console.info("The module has been initialised"); }, add: function(c){ //c doesn't exhist so 0; c = c || 0; var sumA = a + c; var sumB = b + c; console.log(sumA); console.log(sumB); } } }(); myModule.init();//Initialise myModule.add(33);
Initial URL
Initial Description
Simple illustration of structuring your JavaScript and minimising your use of global vars.
Initial Title
Module layout in JavaScript
Initial Tags
module
Initial Language
JavaScript