parseInt and implicit octal constants

Garrett Smith dhtmlkitchen at gmail.com
Sun Feb 22 15:13:02 PST 2009


On Sun, Feb 22, 2009 at 9:30 AM, Allen Wirfs-Brock
<Allen.Wirfs-Brock at microsoft.com> wrote:
> David-Sarah Hopwood wrote:
>>
>>Herman Venter wrote:


> Finally, there is another approach to resolving this issue.  Define a new global function, parseInteger, that does the "right thing" and relegate parseInt to Annex B.
>

That is a good idea, but I wonder: Would programs use that?

a program could use:

  i = parseInt(x)

- which can result in undesirable behavior. That is fixed by:-

  i = parseInt(x, 10)

- or the proposal:-

  if(typeof parseInteger == "function") {
    i = parseInteger(x);
  } else {
    i = parseInt(x, 10);
  }

-which seems a bit clunky. How about just:-

  i = parseInteger(x)

but that last one may result in an error, should the implementation
not support the new function. Programs that use parseInt(x, 10) will
work in more implementations.

Garrett


More information about the Es-discuss mailing list