title: Javascript - Apply trim function to each string in an array
body: <p>Want to trim each string in an array, e.g., given</p>
  
  <pre><code>x = [' aa ', ' bb '];
  </code></pre>
  
  <p>output</p>
  
  <pre><code>['aa', 'bb']
  </code></pre>
  
  <p>My first trial is</p>
  
  <pre><code>x.map(String.prototype.trim.apply)
  </code></pre>
  
  <p>It got "TypeError: Function.prototype.apply was called on undefined, which is a undefined and not a function" in chromium.</p>
  
  <p>Then I tried</p>
  
  <pre><code>x.map(function(s) { return String.prototype.trim.apply(s); });
  </code></pre>
  
  <p>It works. What's the difference?</p>