According to this MDN page, toLocaleString
is about converting dates. However, Chrome exposes the function on more than strings. For example:
a = function () {};
a.toLocaleString(); // "function () {}"
What is the toLocaleString
? Why is it exposed, for example, on the empty function?
It's also available on Object.prototype
, so indirectly on pretty much anything.
For Chrome, you can look at V8's implementation, which doesn't do anything fancy:
function ObjectToLocaleString() {
if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
throw MakeTypeError("called_on_null_or_undefined",
["Object.prototype.toLocaleString"]);
}
return this.toString(); // <-- just calls toString
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With