You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We can make the constructor a lot more robust by removing the value instanceof Decimal type guard.
The problem with this guard is that you can get false negatives (esp if you end up with different versions of Decimal in your project, for whatever reason). This causes very difficult-to-trace issues where code will throw on valid inputs depending on where the source object was constructed.
The condition probably doesn't need to be quite so restrictive. What if it was replaced with duck-typing? (this could also help in dumping to/from json).
And then the trickier one you missed out: checking if value.d is an array using ECMAScript 3 features only (or just use typeof value.d == 'object', of course).
It's quite a lot of duck-typing on a very hot code path, for the probably rare case when for some reason there are multiple versions of Decimal present (which could in any case be handled albeit less efficiently by calling toString on their instances when passing them to a different Decimal's methods).
Anyway, you make some fair points, and I will leave this issue open for consideration. Thanks for your input.
Thanks for the consideration. I'd be happy to contribute if you can think of something acceptable (I'm aware that I'm probably in a small minority with this issue!)
We can make the constructor a lot more robust by removing the
value instanceof Decimal
type guard.The problem with this guard is that you can get false negatives (esp if you end up with different versions of Decimal in your project, for whatever reason). This causes very difficult-to-trace issues where code will throw on valid inputs depending on where the source object was constructed.
The condition probably doesn't need to be quite so restrictive. What if it was replaced with duck-typing? (this could also help in dumping to/from json).
The text was updated successfully, but these errors were encountered: