detect HTMLCollection/NodeList in JavaScript
<p>here is my solution, but i am not sure it is available all the time.</p>

<pre><code>function isNodeList(nodes) {
    var result = Object.prototype.toString.call(nodes);
    // modern browser such as IE9 / firefox / chrome etc.
    if (result === '[object HTMLCollection]' || result === '[object NodeList]') {
        return true;
    }
    //ie 6/7/8
    if (typeof(nodes) != 'object') {
        return false;
    }
    // detect length and item 
    if (!('length' in nodes) || !('item' in nodes)) {
        return false;
    }
    // use the trick NodeList(index),all browsers support
    try {
        if (nodes(0) === null || (nodes(0) &amp;&amp; nodes(0).tagName)) return true;
    }
    catch (e) {
        return false;
    }
    return false;
}
</code></pre>

<p>one common situation we must consider is {length:1,item:function(){return [];}}<br/>
any better solutions?<br/>
one more question is about HTMLCollection and NodeList.<br/>
the value of result in chrome / safari / opera is '[object NodeList]'.<br/>
In firefox and IE 9 , it is '[object HTMLCollection]'.<br/>
which is the standard value? personally i agree with HTMLCollection.</p>
