I\'ve seen some discussions on SO regarding $(this)
vs $this
in jQuery, and they make sense to me. (See discussion here for an example.)
Bu
You usually use var $this = $(this);
to avoid creating a new jQuery object more often than necessary. In case of the code below you only create one object instead of two/four. It is completely unrelated to chainability.
You could also call it that
, $thi$
or anything else (don't use the latter one though, it's ugly :p) as $
is just a simple character in JavaScript, exactly like a-z are.
Inside $.fn.lockDimensions
, this
is the jQuery object that had lockDimensions
called on it.
Inside the .each
, this
now references the DOMElement in the current iteration of the loop. $(this)
wraps the DOMElement in a jQuery object, and var $this = $(this);
is just saving $(this)
in a variable called $this
, so the jQuery constructor doesn't need to be called multiple times (if you were to use $(this)
instead).
$this = $(this)
which means that you are assigning the current object to a variable named $this
. It is not a keyword.
It is just a variable name.