hugoware / jlinq-beta

Total rewrite of jLinq - Public beta code

Home Page:http://hugoware.net/projects/jlinq

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

avoid generating more globals than needed

millermedeiros opened this issue · comments

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;