-
Notifications
You must be signed in to change notification settings - Fork 417
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove current behavior of Big(undefined)
#220
Comments
It's too late, I think. That decision was made years ago. It's unconventional but it's short and sweet and I'm okay with it.
Anyway, using Thanks for the feedback. |
I was thinking import Big, {createBig} from 'big.js';
Not always true, for example in this case, function sum(array, initialValue) {
return array.reduce((total, current) => total.plus(current), Big(initialValue))
}
console.log(sum([1,2,3], 0).toString()) // -> "6"
console.log(sum([], undefined).toString()) // -> The `Big` constructor |
In my project, I added a simple wrapper, to enforce import Big from 'big.js';
class BigNumber {
constrictor(value) {
if (value === undefined) {
throw new TypeError('...')
}
return new Big(value)
}
}
export default BigNumber; Didn't subclass since I'm not sure if it will work when I wrote it. Just want to share how I use, and feel worth a try to propose a change to prevent such mistakes. |
This comment has been minimized.
This comment has been minimized.
Maybe we can check So the change will be almost unnoticeable. |
Sorry, I'm not seeing any compelling arguments. Your wrapper seems a bit pointless when Big.create = n => new Big(n); That way, you wouldn't have to create instances using
Which behaviour? None of the others create a new constructor by calling the default constructor without |
That's exactly why I use
Really sorry, I read them too quick, I saw |
https://mikemcl.github.io/big.js/#big
It's too dangerous to return a new class instead of
Big
instance, users need check every input first.of course, we still need to be careful to not pass
undefined
, but we can throw onBig(undefined)
, that's much easier to use and get noted.To support creating new
Big
class, we can exposecreateBig()
instead.The text was updated successfully, but these errors were encountered: