我知道 HTMLCollection 实际上不是一个数组,否则它将被定义为一个数组。我使用称为 isArray() 的帮助函数来检测对象是否为数组。我到处使用这个小助手,并且在检查 htmlCollection 时,我一直在运行返回 false 的问题。
var isArray: function(obj) {
var type = Function.prototype.call.bind( Object.prototype.toString );
return type(obj) === '[object Array]' || type(obj) === '[object HTMLCollection]';
}
在这个辅助函数中检查 htmlCollection 类型并假设它与数组相同,会不会出错?是什么让它与众不同?除了它的 html 元素而不是 javascript 对象。