title: Having trouble with DOM nodes and instanceof
body: <p>OK, I have a little function walking the tree like this:</p>
  
  <pre><code>function walkTree(node, func, args) {
      func(node, args);
      node = node.firstChild;
      while (node) {
          walkTree(node, func, args);
          node = node.nextSibling;
      }
  }
  </code></pre>
  
  <p>And another function that would pick up only the text nodes like so:</p>
  
  <pre><code>function selectTextNodes(node, nodes) {
      if (node instanceof Text) {
          nodes.push(node);
      }
  }
  </code></pre>
  
  <p>And finally, using both:</p>
  
  <pre><code>texts = [];
  walkTree(body, selectTextNodes, texts);
  </code></pre>
  
  <p>However, it doesn't fill the list at all!</p>
  
  <p>If I were to modify the test as to use <code>Node.nodeType</code> it would work:</p>
  
  <pre><code>function selectTextNodes(node, nodes) {
      if (node.nodeType == Node.TEXT_NODE) {
          nodes.push(node);
      }
  }
  </code></pre>
  
  <p>On the other hand, in the console it works both ways:</p>
  
  <pre><code>t = window.document.createTextNode("test");
  r = (t.nodeType == Node.TEXT_NODE) &amp;&amp; (t instanceof Text);
  </code></pre>
  
  <p>That is, r is true.</p>
  
  <p>Note that, all functions are nested inside another function that receives the <code>body</code> variable. In my case, this is the <code>contentDocument.body</code> of an <code>iframe</code>. There is no x-domain restriction being applied.</p>
  
  <p>Any idea what's going on?</p>