Reputation: 265
i have a simple question about caching, this kind of confuses me lol Im not sure if it depends on if your using handlers or not but...
is there any difference between these two?
var $something = $('.something');
or
var something = $('.something');
and also, is it possible to do this (depending on the correct way)
var something = $('something'),
somethingElse = $('somethingelse');
or this way
var something = $('something');
var somethingElse = $('somethingelse');
just want to be sure im heading in the right direction.
It's been bothering me. I've seen it done both ways actually, but i don't know which is right, or if either are wrong. I'm sure someone knows for sure though :)
Upvotes: 1
Views: 133
Reputation: 723468
It's your choice. Many people (including myself) prefix variables with $
to indicate that the variables represent jQuery objects (because $
is shorthand for jQuery
). If you think it helps you along the same lines, then you're free to prefix your variables as such.
Declaring multiple variables comma-separated with a single var
keyword is legal JavaScript.
Upvotes: 1
Reputation: 41812
Prefixing variables with $
is only used to remind the programmer (or others) that the variable holds a jquery object. It isn't a 'javascript thing' and does not provide any additional functionality. It's a good idea though :)
All the code you posted is valid.
Upvotes: 2