Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.