Skip to content

Javascript global scope alternatives

Sébastien LUCAS edited this page Sep 5, 2013 · 2 revisions

It's bad pratice to throw everything in the window object, which is the global scope in js There is alternatives you can find all listed in the book
Javascript The good parts

  • Define you new functions as a jquery plugin
$.urlParam = function(name){
    var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
    if (results==null){
       return null;
    }
    else{
       return results[1] || 0;
    }
}

WIKI by Sébastien Lucas CEO & Funder or Bricks

Clone this wiki locally