caching - Does jQuery $(this) need to be cached -


I've recently come across some blog posts about jQuery's performance (i.e.) and all of them have been said That we should cache JQuery objects to JavaScript variables.

What I need to know, though, is that it applies to $ (this) also if I do this, I will get it in the performance:

  $ ("# Some-link"). Click ("click", function () {var $ this = $ (this); $ This.doSomeThing ();});  

Thank you in advance for your help.

This can reference many different objects.

Caching $ (this) can not be important, because this is already running element and thus jQuery DOM search for this element There is no need to do

Although in a function if you call $ (this) more than once, then it is wise to put $ (this) There is $ (this) variable instead of making calls. Click

  $ ("# some-link") ("click", function () {var $ this = $ (this); $ this.doSomeThing (); $ this DoThisThing (); $ this.doThatThing ();});  

  will be more efficient than $ ("# some-link"). Click ("click", function () {$ (this) .doSomeThing (); $ (this) .doThisThing (); $ (this) .doThatThing ();});  

Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

jquery - SimpleModal Confirm fails to submit form -

php - Multiple Select with Explode: only returns the word "Array" -