Skip to content
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

Default coercion functions not compatible with parseInt and default #524

Closed
Slowlearneruk opened this issue Apr 19, 2016 · 2 comments
Closed

Comments

@Slowlearneruk
Copy link

The coercion functions when sent are passed the raw option value as parameter one and if set, then the default parameter is sent as the second argument. Therefore if you try using the example option with parseInt but add a default, the result will sometimes succeed and sometimes fail because the second parameter to parseInt is the number base (default base 10).

I imagine changing this now is going to break backwards compatibility - can I suggest that in the prototype.option command you might test to see if fn === parseInt (or parseFloat) and pass arguments appropritely.

Alternatively is probably worth not using parseInt as your example and instead pass function(sRaw) { return parseInt(sRaw, 10); }

If you are happy to risk breaking backward compatibility then I would recommend not passing the default value as a second parameter. The function is really meant for coercing type I assume and the caller is going to know the default anyway.

@reconbot
Copy link

dupe of #400

@shadowspawn
Copy link
Collaborator

Closing as covered by #201 and #943

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants