.find()是否比基本后代选择方法快? [英] Is .find() faster than basic descendant selecting method?

查看:72
本文介绍了.find()是否比基本后代选择方法快?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Paul Irish的博客中提到的第30张幻灯片:

Slide 30 in Paul Irish's blog mentioned:

$('#container').find('div.robotarm')快于$('#container div.robotarm')

这是真的吗?

推荐答案

也许是在早期版本的jQuery中.但是,表达式

Maybe in an earlier version of jQuery that was the case. However, the expression

$('#container div.robotarm')

通过jQuery标准化为

is normalized through jQuery into

$('#container').find('div.robotarm')

所以$('#container div.robotarm')应该变慢的唯一原因是由于函数调用开销.但是,那确实是微不足道的区别.

So the only reason why $('#container div.robotarm') should be slower is because of function call overhead. But, that would really be a trivial difference.

如果该调用未规范化,则将使用sizzle(Resigs CSS选择器引擎)查找该元素(从右到左).那当然会慢得多.

If that call wasn't normalized, sizzle (Resigs css selector engine) would be used to lookup that element (right to left). That of course would be much slower.

这篇关于.find()是否比基本后代选择方法快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆