Skip to content

Instantly share code, notes, and snippets.

@Southern
Forked from garrettwilkin/gist:3642279
Created September 5, 2012 18:42
Show Gist options
  • Save Southern/3642328 to your computer and use it in GitHub Desktop.
Save Southern/3642328 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