Maximun call stack size error on recursive iterator
<p>I'm experimenting with JavaScript, and just for learning purposes, I was writing a forEach iterator that can iterate trough nested arrays or any other iterable object that include a <code>length property</code>.</p>

<p>This is what I wrote:</p>

<pre><code>var forEach = function(obj, callback, options) {
  var options = options || {};
  var context = options.context || this;    

  if(!isEmpty(obj)) { // isEmpty function just evaluates `return !(!!obj.length);`
    for(var x = 0; x &lt; obj.length; x++) {
      if(!isEmpty(obj[x]) &amp;&amp; options.deep === true) {
        forEach.call(context, obj[x], callback, options);
        continue;
      }
      callback.call(context, obj[x]);
    }
  }
};
</code></pre>

<p>If I pass a nested array I get <code>RangeError: Maximum call stack size exceeded</code>:</p>

<pre><code>forEach(['a', 'b', ['c', 'd']], function(x) {
  console.log(x);
}, { deep: true });
</code></pre>

<p>But that only seems to happen if I check for length property in <code>obj[x]</code></p>

<p>If I replace:</p>

<pre><code>if(!isEmpty(obj[x]) &amp;&amp; options.deep === true) {
</code></pre>

<p>For:</p>

<pre><code>if((obj[x] instanceof Array) &amp;&amp; options.deep === true) {
</code></pre>

<p>I will magically work. Hovewer, not only <code>Arrays</code> have a length property. <code>String</code> have it to, so It's not a wide approach. </p>

<p>How can I prevent the <code>RangeError</code> but still check for <code>length property</code>?</p>

<p><strong>EDIT:</strong> I'm running the example on <strong>NodeJS v0.8.12</strong></p>
