速度[] .forEach.call(...? [英] Speed of [].forEach.call(...?
本文介绍了速度[] .forEach.call(...?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
var nodes = document.querySelectorAll( 包含.foo);
[] .forEach.call(nodes,function(item){
// do items with item
});
我想知道,做这种方式需要比常规方法更长的时间吗?
例如
pre $ for(var i = 0; i< nodes.length; i ++){
/ /做节点的东西[我];
解决方案
这里有一个不错的表现比较。根据,Array.forEach
比循环的本地慢。
I'm a big fan of using the forEach method on nodeLists like this:
var nodes = document.querySelectorAll(".foo");
[].forEach.call(nodes, function (item) {
//do stuff with item
});
I was wondering though, does doing it that way take longer than the regular way? e.g.
for(var i=0;i<nodes.length;i++){
//do stuff with nodes[i];
}
解决方案
Here's a nice performance comparison. According to it Array.forEach
is slower than a native for
loop.
这篇关于速度[] .forEach.call(...?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文