Skip to content

Commit 9b7afbf

Browse files
committed
Prefix selector caches with a dollar symbol
to help identify them as such later on in the code. This is a fairly common jQuery pattern: http://stackoverflow.com/questions/6209462/when-why-to-prefix-variables-with-when-using-jquery http://encosia.com/5-steps-toward-jquery-mastery/
1 parent adb7570 commit 9b7afbf

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

jquery-patterns/cache-selector.html

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,16 @@
1717

1818

1919
// preferred
20-
var photo;
20+
var $photo;
21+
// prefix the cache with $ to help identify it as a selector cache later
2122
$('.list-item').click(function () {
22-
photo = photo || $('.photo');
23-
photo.hide();
23+
$photo = $photo || $('.photo');
24+
$photo.hide();
2425
});
2526

2627

2728
// References
2829
// http://ejohn.org/blog/learning-from-twitter/
2930
</script>
3031
</body>
31-
</html>
32+
</html>

0 commit comments

Comments
 (0)