Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid generating more globals than needed #6

Open
millermedeiros opened this issue Sep 9, 2011 · 0 comments
Open

avoid generating more globals than needed #6

millermedeiros opened this issue Sep 9, 2011 · 0 comments

Comments

@millermedeiros
Copy link

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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant