Internationalization: Strings as locales argument

Brendan Eich brendan at
Fri Jul 13 15:44:16 PDT 2012

Norbert Lindenberg wrote:
> (3) If locales is a String value, then
> (3a)    Let locales be a new array created as if by the expression new Array(locales) where Array is the standard built-in constructor with that name and locales is the value of locales.
> The result would be that "" is rejected with a RangeError, but "en-US" is processed as ["en-US"].
> Any objections?

No, looks good -- using the standard built-in constructor makes the 
temporary Array instance unobservable. Clearly the right answer is to 
special-case a String-type argument before falling back on ToObject. One 
might question using ToObject at all, though. If you really only expect 
a string or else an object with indexed elements bounded by .length, you 
could throw on non-string primitives.

The ToObject uses in clause 15 in ECMA-262 are mostly for processing 
|this| when passed to a generic Array method, with a lesser cohort in 
15.2.* for Object prototype and constructor methods. Not IMHO strong 
precedent for new locale/locale-list-bearing APIs.


More information about the es-discuss mailing list