The developers I know often repeat the same jQuery selectors, rather than storing the result in a variable. They are consistent with this approach.
For example, they do this:
var propName = $(this).attr('data-inv-name'); var propValue = $(this).attr('data-inv-value');
Instead of this:
var current = $(this); var propName = current.attr('data-inv-name'); var propValue = current.attr('data-inv-value');
The latter approach seems correct to me, but maybe I missed something. This is a simple example, but I saw that $ (this) is repeated dozens of times in the same function.
What is the best practice for developing with jQuery? Are call switches repeated or stored in a variable?
Joe b source share