string Array.prototype.toLocaleString() throws TypeError
This function should output the same as its toString brother but takes a whole different approach because it can use a locale seperator. This seperator is gotten in a implementation based way. After that it manually applies the join (so join doesn't get called and it doesn't fall back to Object.prototype.toString if join is absent).
Note that all elements in the array (after coercion to object) must have a callable toLocaleString property or this function throws a TypeError.
The this value will be coerced to an object.
Array.prototype.toLocaleString = function(){
var O = ToObject(this);
var arrayLen = array.[[Get]]("length");
var len = ToUint32(arrayLen);
var separator = ", "; // or through any other implementation dependent method
if (len == 0) return '';
var firstElement = array.[[Get]]("0");
if (firstElement === undefined || firstElement === null) var R = '';
else {
var elementObj = ToObject(firstElement);
var func = elementObj.[[Get]]("toLocaleString");
if (!IsCallable(func)) throw TypeError;
var R = func.[[Call]](elementObj, []);
}
var k = 1;
while (k < len) {
var S = R + separator;
var nextElement = array.[[Get]](ToString(k));
if (nextElement === undefined || nextElement === null) R = "";
else {
var elementObj = ToObject(nextElement);
var func = elementObj.[[Get]]("toLocaleString");
if (!IsCallable(func)) throw TypeError;
R = func.[[Call]](elementObj, []);
}
R = S + R;
}
}
The specification notes that the first parameter should not be used as it might be used in a future specification.