Why is this "invalid calling object" error?
<p>I write the following JS and run in IE 10:</p>

<pre><code>function test() {
    var nodes = document.getElementsByTagName("h1");
    document.writeln(nodes.length);
    for (var j = 0; j &lt; nodes.length; j++) {   &lt;=== THIS LINE!
        document.writeln(j.toString());
        }
    document.writeln("abc");
}
</code></pre>

<p>But I kept get "invalid calling object" error for the marked line.</p>

<p>Why?</p>

<p>And here is my page source:</p>

<pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml" &gt;
    &lt;head&gt;
        &lt;title&gt;This is JS fun!&lt;/title&gt;
        &lt;script type="text/javascript" language="javascript" src="test.js"&gt;
        &lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;h1&gt;1111&lt;/h1&gt;   
        &lt;h1&gt;2222&lt;/h1&gt;   
        &lt;h1&gt;3333&lt;/h1&gt;   
        &lt;h1&gt;4444&lt;/h1&gt;   
            &lt;input type="button" onclick="test()" value="click me!" /&gt;
    &lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>Below is my screenshot:</p>

<p><img src="http://i.stack.imgur.com/rC5YS.png" alt="enter image description here"></p>
