Performance of jQuery selector with context

后端 未结 6 1432
南方客
南方客 2020-12-01 05:26

I was reading this article by Brandon Aaron here, about how jquery context may help. So i thought of doing a test of my own. So this is what I did.

  1. Created

6条回答
  •  栀梦
    栀梦 (楼主)
    2020-12-01 06:19

    Be careful before you going to refactor your code. As in the #NOTE written, jQuery since 1.4 works quite different way. The latest version may contain even more optimizations.

    I modified the jsbin code above to have the recent jQuery, and added some additional cases as well. You will see, now only those three (2,3,6) cases got performance penalty which creates one more jQuery object per round. Rest runs in quite same time.

    You can find the modified version here: http://jsbin.com/aciji4/63/

提交回复
热议问题