Instead of asking a question, I just wanted this to be a problem, but so far I have not been able to find the answer.
For example, we have an array of strings
x = ['a', ' b', ' c ']
and I want to trim all the elements. I tried the methods applyand callbut did not work properly:
x.forEach(String.prototype.trim.call)
// Uncaught TypeError: undefined is not a function
x.forEach(String.prototype.trim.apply)
// Uncaught TypeError: Function.prototype.apply was called on undefined, which is a undefined and not a function
What's going on here? apply/ callshould take its first argument from each function, and everything seems fine.
source
share