JavaScript: Creating Your Own Global Namespace March 18th, 2013

Start with a global object variable declaration and extend that object with properties…

var wnt = {}; //Start with the global declaration
wnt.util = {}; //Add a new level (if desired)
wnt.util.urlparameter = function(name) {
    return decodeURI(
        (RegExp(name + ‘=’ + ‘(.+?)(&|$)’).exec(location.search)||[,null])[1]
    );
}; //Turn a level into a method
alert(eval(wnt.util.urlparameter(‘page’))-1); //assumes URL ends with ?page=n and subtracts one so it can be used in conjunction with $.eq() to count in a 0-based array.