想要修剪数组中的每个字符串,例如,给定
x = [' aa ', ' bb '];
输出
['aa', 'bb']
我的第一次试验是
x.map(String.prototype.trim.apply)
它在铬中得到“TypeError: Function.prototype.apply was called on undefined, which is an undefined and not a function”。
然后我尝试了
x.map(function(s) { return String.prototype.trim.apply(s); });
有用。有什么不同?