each implementation in the underscore.js library
<p>Question about the implementation of the "each" function I found in the underscore.js source code (source below).  </p>

<p>First, could someone explain what the line "else if (obj.length === +obj.length) " is checking for.</p>

<p>Second, could someone explain why hasOwnProperty.call(obj, key) is used, as opposed to obj.hasOwnProperty?  Is it because the passed in obj may not implement hasOwnProperty (which I thought every javascript object did)</p>

<p>any insights appreciated. Thanks.</p>

<pre><code>  // The cornerstone, an `each` implementation, aka `forEach`.
  // Handles objects with the built-in `forEach`, arrays, and raw objects.
  // Delegates to **ECMAScript 5**'s native `forEach` if available.

  var each = _.each = _.forEach = function(obj, iterator, context) {

    if (obj == null) return;
    if (nativeForEach &amp;&amp; obj.forEach === nativeForEach) {
      obj.forEach(iterator, context);
    } else if (obj.length === +obj.length) {
      for (var i = 0, l = obj.length; i &lt; l; i++) {
        if (i in obj &amp;&amp; iterator.call(context, obj[i], i, obj) === breaker) return;

      }
    } else {
      for (var key in obj) {
        if (hasOwnProperty.call(obj, key)) {
          if (iterator.call(context, obj[key], key, obj) === breaker) return;
        }
      }
    }
  };
</code></pre>
