length property of re-specified locale sensitive methods

Norbert Lindenberg ecmascript at norbertlindenberg.com
Mon Jul 9 12:48:03 PDT 2012

The ECMAScript Internationalization API Specification re-specifies several locale sensitive functions of the ECMAScript Language Specification by adding two arguments, locales and options:
- String.prototype.localeCompare
- Number.prototype.toLocaleString
- Date.prototype.toLocaleString
- Date.prototype.toLocaleDateString
- Date.prototype.toLocaleTimeString

Neither of the two specifications directly specify the length properties of these functions, so the introduction of ES5.1 clause 15 applies: "this value is equal to the largest number of named arguments shown in the subclause headings for the function description, including optional parameters."

Using this rule, the values of the length properties would increase by two for these functions due to the re-specification. However, we could also apply the rule that Allen proposed a while ago [1], i.e., not count the new arguments because they're optional. Either way, I think the spec needs to address this.

From an application point of view, I think increasing the length value would be useful: It gives applications a direct way to detect whether the functions will interpret or ignore locales or options arguments.

test262 checks the length values of most of the methods (not Number.prototype.toLocaleString). I don't know whether in web reality anybody depends on the current values of the length properties of these functions.

The API designer in me leans towards increasing the length values, but I expect Allen to twist my arm the other way...



[1] https://mail.mozilla.org/pipermail/es-discuss/2011-August/016361.html

More information about the es-discuss mailing list