Skip to content

Instantly share code, notes, and snippets.

@ovaillancourt
Created April 5, 2012 00:04
Show Gist options
  • Save ovaillancourt/2306692 to your computer and use it in GitHub Desktop.
Save ovaillancourt/2306692 to your computer and use it in GitHub Desktop.
Using a closure or wrapped function
//That's your route
function(req,res,next){
var username = req.session.username;
var filteredArray = _.filter(myArray,function(value){
return value == username; //username is in your closure there...
});
}
//That's your route
function(req,res,next){
var myWrappedIterator = function(username){
return function(value){ return username == value;}; //That's another closure actually... but in a wrapped function.
}
var filteredArray = _.filter(myArray,myWrappedIterator(req.session.username));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment