2.1.65 [ECMA-262-1999] Section 15.4.4.3, Array.prototype.toLocaleString ()

V0099:

The elements of the array are converted to strings using their toLocaleString methods, and these strings are then concatenated, separated by occurrences of a separator string that has been derived in an implementation-defined locale-specific way. The result of calling this function is intended to be analogous to the result of toString, except that the result of this function is intended to be locale-specific.

The result is calculated as follows:

  1. Call the [[Get]] method of this object with argument "length".

  2. Call ToUint32(Result(1)).

  3. Let separator be the list-separator string appropriate for the host environment's current locale (this is derived in an implementation-defined way).

  4. Call ToString(separator).

  5. If Result(2) is zero, return the empty string.

  6. Call the [[Get]] method of this object with argument "0".

    1. __If Type(Result(6)) is VarDate, let R be "[object Object]" and then go to step 9.__

  7. If Result(6) is undefined or null, use the empty string; otherwise, call ToObject(Result(6)).toLocaleString(). __If the recursive call to toLocaleString would cause a non-terminating recursion use the empty string as the result of this step.__

  8. Let R be Result(7).

  9. Let k be 1.

  10. If k equals Result(2), return R.

  11. Let S be a string value produced by concatenating R and Result(4).

  12. Call the [[Get]] method of this object with argument ToString(k).

    1. __If Type(Result(12)) is VarDate, use "[object Object]" as Result(13) and then go to step 14.__

  13. If Result(12) is undefined or null, use the empty string; otherwise, call ToObject(Result(12)).toLocaleString(). __If the recursive call to toLocaleString would cause a non-terminating recursion use the empty string as the result of this step.__

  14. Let R be a string value produced by concatenating S and Result(13).

  15. Increase k by 1.

  16. Go to step 10.

The toLocaleString function is not generic; it throws a TypeError exception if its this value is not an Array object. Therefore, it cannot be transferred to other kinds of objects for use as a method.

JScript 5.x determines the separator in step 3 by using the Windows GetLocaleInfo system function and requesting the LOCALE_SLIST value for the current user locale.