Fixed a typo in the code; added section on "real currying".

This commit is contained in:
Martin Danielsson 2016-07-08 08:39:53 +02:00 committed by GitHub
parent c4cc734166
commit 31157d8524

View file

@ -121,7 +121,7 @@ app.get('/users/statistics', function (req, res, next) {
}, function (err, apiRes, apiBody) { }, function (err, apiRes, apiBody) {
if (err) if (err)
return callback(err); return callback(err);
callback(null, JSON.parse(body)); callback(null, JSON.parse(apiBody));
}); });
}, },
function (err, results) { function (err, results) {
@ -201,6 +201,8 @@ The really interesting bit here is the `execHandler`. It's defining a function w
On a side note, we're once more using `async` here, this time the `series()` functionality, which calls the async functions one after the other and returns the results after the last one has finished, or stops immediately if one fails. On a side note, we're once more using `async` here, this time the `series()` functionality, which calls the async functions one after the other and returns the results after the last one has finished, or stops immediately if one fails.
**Footnote 2**: If you're in nitpicking mode, what I describe above is not the classical "currying" you might know from real functional languages such as Haskell or SML, where currying means automatic partial parameter evaluation. This is something you may also do in JavaScript, but you don't get it as a language construct as in Haskell. Perhaps I should just call it "parameterized function definition" or something similar, as that's more to the point.
### On `callback` and `err` parameters, exceptions ### On `callback` and `err` parameters, exceptions
There's a last small thing which I found out about most node.js libraries, and probably I'm just too thick to find this written out someplace, so I do it here: If you're dealing with async functions (and, remember, you are, most of the time), follow these conventions: There's a last small thing which I found out about most node.js libraries, and probably I'm just too thick to find this written out someplace, so I do it here: If you're dealing with async functions (and, remember, you are, most of the time), follow these conventions: