Skip to content

Instantly share code, notes, and snippets.

@garrettwilkin
Forked from Southern/gist:3642328
Created September 5, 2012 19:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garrettwilkin/3642610 to your computer and use it in GitHub Desktop.
Save garrettwilkin/3642610 to your computer and use it in GitHub Desktop.
What the scope?
function findHandler(err, docs) {
if (!err) {
// Return Success & JSON Content-type
var length = docs.length;
writeMeta(self.res,200,url,length);
// Process results from Mongo
docs.forEach(function(e,i,a) {
//console.log(e,i,a);
self.res.write(JSON.stringify(e)+'\n');
});
self.res.end('\n');
} else {
getHandlerError(self.res,url);
}
}
// Normal passing
var func = function(findHandler) {
console.log(findHandler);
};
func(findHandler);
// Wrapped
var func = (function(findHandler) {
return function() {
console.log(findHandler);
};
})(findHandler);
func();
// Wrapped, again, but not immediately assigned.
var func = (function(findHandler) {
return function() {
console.log(findHandler);
};
});
// Call the wrapper function and assign the handler.
var myFunc = func(findHandler);
// Finally call `console.log`
myFunc();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment