4

Why does Sizzle evaluate selectors from right to left? Can anybody give me examples to explain why it will be faster when the selectors are evaluated from right to left than from left to right?

As this mentioned, browser is different from the usual jQuery thing. If it isn't a matter of being faster, does it only follow how selectors works in browser, although it is not a good choice for selecting a collection of elements?

Community
  • 1
  • 1
Light
  • 474
  • 5
  • 15
  • 1
    http://stackoverflow.com/questions/13678702/how-is-the-jquery-selector-foo-a-evaluated, http://code.tutsplus.com/tutorials/quick-tip-think-right-to-left-with-jquery--net-18052, http://blog.bigbinary.com/2010/02/15/how-jquery-selects-elements-using-sizzle.html, http://davidwalsh.name/selectors – j08691 Oct 08 '14 at 02:35

1 Answers1

2

It's not a matter of right-to-left being "faster", but rather because that's how CSS selectors work

SomeKittens
  • 38,868
  • 19
  • 114
  • 143
  • @Light I'm not sure what you mean: "Why does a CSS selector follow how CSS selectors work?" – SomeKittens Oct 10 '14 at 03:09
  • I'm not sure what you mean by "being how CSS selectors work". – Light Oct 10 '14 at 03:11
  • As [this](http://stackoverflow.com/questions/5797014/why-do-browsers-match-css-selectors-from-right-to-left/5813672#5813672) mentioned, browser is different from the usual jQuery thing. So do you mean that it only follows how selectors works in browser, although it is not a good choice for selecting a collection of elements? – Light Oct 10 '14 at 03:27
  • I did read **all** of the links but I all I found are that Sizzle does evaluate selectors from right to left and how Sizzle evaluates selectors, not why Sizzle behaves same way as CSS selectors to select elements. I'm afraid I missed the reason. Would you mind pointing it out, please? – Light Oct 11 '14 at 04:51
  • @Light: Your question is something only John Resig or someone from jQuery Core could answer. The linked question - about CSS selectors - was answered by a Firefox dev, which is as authoritative as it gets. – BoltClock Nov 24 '14 at 13:04