Proposal: a more consistent and stricter number converting function - Number.of()
T.J. Crowder
tj.crowder at farsightsoftware.com
Fri Feb 24 12:15:46 UTC 2017
>
> * If you know that your input is either a string or null/undefined (e.g.,
> as the result of `someHTMLElement.getAttribute('foo')`), you could use
> `Number.parseFloat()`, which will produce NaN for the empty string, null
> and undefined.
>
Of course, `Number.parseFloat("23.4ducky")` results in `23.4`. Duan
indicated he/she wanted this `Number.of` to be more strict.
I, too, have wanted something *strict* that didn't convert `""` and `null`
to `0`. (Like many, I suspect, I have one in my toolkit; but the idea of
something in the standard library appeals.)
-- T.J.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20170224/b68b2d4f/attachment.html>
More information about the es-discuss
mailing list