In this Blog article: "We have a problem with promises", I came upon this code snippet:
somePromise().then(function () {
return anotherPromise();
}).then(function () {
return yetAnotherPromise();
}).catch(console.log.bind(console)); // <-- this is badass
What puzzles me here is the last line, the 'badass' one. I had never had to use the 'bind' method anywhere up until now and am not really knowledgable in JavaScript. Having now just read about the bind method in the Mozilla Developer Network docs, I understand that one can assign a different "this" object, to any function with it (and also hard-insert predefined arguments, so that they become 'non-arguments' to the returned function).
However, as far as I understand, console.log.bind(console)
should be simply the same as console.log
. What is the difference? What have I missed or misunderstood here, and why is this kind of construct used?
Thanks.