The Bluebird docs for the .call method have a code sample labeled, "Chaining lo-dash or underscore methods".
What is the purpose of the chained .then(_) in the code snippet below?
var Promise = require("bluebird");
...
var _ = require("lodash");
var fs = Promise.promisifyAll(require("fs"));
fs.readdirAsync(".").then(_) <-- ???
.call("groupBy", function(fileName) {
return fileName.charAt(0);
})
...
Thanks!
In underscore the _ identifier is a function as well as a namespace.
Doing .then returns the result of the passed function.
Calling the _ function starts a underscore chain, any consecutive actions happen on the object passed. It starts a chain with the result of readdirAsync.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With