-
-
Save Southern/3642328 to your computer and use it in GitHub Desktop.
What the scope?
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
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