开发者社区 问答 正文

关于Array.prototype.filter.call的问题

有这样一段代码:

function traverse(){

return Array.prototype.filter.call(document.querySelectorAll('body *'), function(node){
    return node.offsetWidth > 50 && node.offsetHeight > 50;
});

}
1.call有两个参数,第一个是指作用域,第二个是参数,这段代码中call不能替换为apply,是否是因为apply要求的第二个参数是数组的原因?
2.document.querySelectorAll('body *')的返回值是nodelist,而nodelist不属于array,filter是数组的方法,为什么可以应用到这里??

展开
收起
a123456678 2016-03-11 16:31:02 2426 分享 版权
1 条回答
写回答
取消 提交回答
问答地址: