title: How to simplify and speed up _.each?
body: <p>The native <code>Array.prototype.forEach()</code> is very slow.  I don't know why.  Also, I don't know why it is implemented in <a href="http://underscorejs.org/#each" rel="nofollow">Underscore.js</a>'s <code>_.each()</code>.  I think people generally think that if it is in a library, or it is implemented by a browser, that it is correct/efficient until proven not correct/efficient.</p>
  
  <p>Here is the proof:</p>
  
  <p><a href="http://jsperf.com/native-vs-implmented-0" rel="nofollow">http://jsperf.com/native-vs-implmented-0</a></p>
  
  <p>If we simply remove the native call from <a href="https://github.com/documentcloud/underscore/blob/master/underscore.js#L77" rel="nofollow">underscore,  _.each</a>, we get:</p>
  
  <pre><code>  var each = _.each = _.forEach = function(obj, iterator, context) {
      if (obj == null) return;
      if (obj.length === +obj.length) {
        for (var i = 0, l = obj.length; i &lt; l; i++) {
          if (iterator.call(context, obj[i], i, obj) === breaker) return;
        }
      } else {
        for (var key in obj) {
          if (_.has(obj, key)) {
            if (iterator.call(context, obj[key], key, obj) === breaker) return;
          }
        }
      }
    };
  </code></pre>
  
  <p>I plan on asking the underscore team as well, but I wanted to verify I did not miss anything obvious.</p>
  
  <p>Is this a valid reduction that will enhance performance?  Is the performance hit taken in the hope that one day it will be faster? Can this reduction be made to enhance performance without losing <em>useful</em> functionality?</p>