|
|
|
|
|
by isntitvacant
5276 days ago
|
|
I'm increasingly a fan of local named functions in JS, vs. pulling callbacks entirely out of scope. An example: function compile(filename, ready) {
return fs.readFile(filename, make_fn)
function make_fn(err, data) {
if(err) return ready(err)
ready(null, new Function(data))
}
}
Which neatly addresses the desire to retain closures, while avoiding unnecessary nesting.Also, whenever possible, I like to nix callbacks by using Function#bind: res.on('data', accum.push.bind(accum))
// vs:
res.on('data', function(data) { accum.push(data) })
|
|