Created
April 5, 2012 00:04
-
-
Save ovaillancourt/2306692 to your computer and use it in GitHub Desktop.
Using a closure or wrapped function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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... | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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