hugoware / jlinq-beta

Total rewrite of jLinq - Public beta code
http://hugoware.net/projects/jlinq
237 stars 59 forks source link

avoid generating more globals than needed #6

Open millermedeiros opened 13 years ago

millermedeiros commented 13 years ago

I think the library shouldn't generate multiple alias (jl, jlinq, jLinq), If the user wants to use an abbreviation it's better that he creates an alias inside his scope:

//closure to avoid polluting global scope and also generates alias to jlinq object 
//since I'm going to call it a lot of times
(function(jl){
     var result = jl.from(myData).contains('awesome', true).select();
     var result2 = jl.from...
}(jlinq));

or:

function doManyQueries(){
  var jl = jlinq; //local alias
  var result = jl.from(myData).contains('awesome', true).select();
  var result2 = jl.from...
}

if you have some legacy code that uses the alias is very easy to fix it, just by adding the property to the global scope, if documented it should be hard to follow:

//create global alias for backward compatibility
window.jl = jlinq;