Я не уверен, что моя текущая реализация доступна все время:
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) && nodes(0).tagName)) return true;
}
catch (e) {
return false;
}
return false;
}
Общей ситуацией является {length: 1, item: function() {return [];}}
Значение результата в chrome/safari/opera - "[object NodeList]".
В firefox и IE 9 это "[object HTMLCollection]".
Какое стандартное значение?