Thanks for the quick reply and tips Kevin, I really appreciate it! :)
I definitely agree with the tips you mention and have been following those rules for a little while now.
My main concern is, if I do cache "this" in a "$this" variable, are there situations where I might run into collisions with nested functions, like animate(), on(), click(), other() if they're using the same named variable to cache $(this)?
I'm probably over-thinking things here. :D
Quick question related to my code:
On lines #17 and #31, why does $this return undefined? Shouldn't the $this from lines #3 and #19 be accessible at that point, just like the $dog variable is? Why didn't the "this" from lines #3 and #19 not get cached for the scopes of the nested functions/callbacks? Did the reference/cache "this" somehow get redefined to "undefined" when I jumped into the click()'s and animate()'s closures?
Here's the output from Firebug's console:
- (billy 1) this: Window 2 $this: jQuery(Document 2) $dog: jQuery(p#dog)
- (1) this:<button id="clickme">$this: undefined$dog:jQuery(p#dog)
- (2) this: <button id="clickme"> $this: jQuery(button#clickme) $dog: jQuery(p#dog)
- (billy 2) this: Window 2 $this: jQuery(Document 2) $dog: jQuery(p#dog)
- (3) this: <div id="what" style="opacity: 0.25; left: 50px; display: none;"> $this: undefined $dog: jQuery(p#dog)
- (4) this: <div id="what" style="opacity: 0.25; left: 50px; display: none;"> $this: jQuery(div#what) $dog: jQuery(p#dog)
Thanks so much for your help! Sorry if n00bie questions. :)