Excuse me if I've something missed, but when I try to use call method as a callback it gives me strange error in both Chrome and Node.js.
[' foo', ' bar '].map(String.prototype.trim.call);
TypeError: [" foo", " bar "].map is not a function
at Array.map (native)
But these snippets works:
[' foo', ' bar '].map(function (item) {
return String.prototype.trim.call(item);
}); // => ['foo', 'bar']
/*
and ES2015
*/
[' foo', ' bar '].map(function () {
return String.prototype.trim.call(...arguments);
}); // => ['foo', 'bar']
Also I've checked type of call
function:
typeof String.prototype.trim.call; // => 'function'
Am I doing something wrong? Could anyone please explain me why I get such error? Thanks.
brevitygolfing will confuse the heck out of anyone. If you do that, you should first eliminate all whitespaces :-) – Bergi Feb 09 '16 at 18:46