p.jaszkow at gmail.com
Wed Oct 11 04:10:41 UTC 2017
True, it's a fairly trivial thing, but so is `Array.prototype.includes`. I
can give a hundred other examples.
There is a reason that so many people use underscore, ramda, lodash, etc:
provide as many of these helpful utilities as possible. Not only does it
improve developer experience, it also reduces payloads people need to
download over the wire.
I can understand why people are hesitant to add _syntactic additions_ to
use via libraries, I can't understand the reservations.
You did provide a good method name (`guard`) if the final decision is to
avoid overloading `catch` (which I don't mind either way, in some ways it
would be preferable so the argument order could be reversed).
Anyways, I think the best implementation would do three things:
1. If `matcher` is a function, check if `matcher.prototype instanceof
Error`, if so, use `instanceof` to check if a rejected error matches
2. If `matcher` is a function that doesn't inherit from `Error`, execute it
with the rejected error to get the match condition
3. If `matcher` is an object, check every own enumerable property against
the rejected error to get the match condition
This seems pretty complicated, in that it doesn't seem to match the
principle of avoiding overloading in the standard library. I think in this
case, removing any of this functionality is a significant loss, but if any
were to be removed, I'd choose #3.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss