This, of course, returns what you would expect:
["A","B","C"].map(function (x) {
return x.toLowerCase();
});
// --> ["a", "b", "c"]
So does using String.prototype.toLowerCase.call:
["A","B","C"].map(function (x) {
return String.prototype.toLowerCase.call(x);
});
// --> ["a", "b", "c"]
It also works if you pass the extra arguments given by map, as it throws away the arguments:
["A","B","C"].map(function (x, index, arr) {
return String.prototype.toLowerCase.call(x, index, arr);
});
// --> ["a", "b", "c"]
But, this does not work:
["A","B","C"].map(String.prototype.toLowerCase.call);
// --> TypeError: undefined is not a function
The following doesn't work either, because arguments
has the Object prototype instead of the Array prototype, so slice
is undefined on it. Is the reason for the above behavior perhaps because of something like this-- where slice
or some other similar Array function is used internally?
["A","B","C"].map(function (x) {
return String.prototype.toLowerCase.apply(x, arguments.slice(1));
});
// --> TypeError: undefined is not a function