Friday, 3 January 2014

using selector cache to avoid requery

 <script>
/* Title: selector cache Description: using selector cache to avoid requery */ // antipattern $('.list-item').click(function () { $('.photo').hide(); }); // preferred var $photo; // prefix the cache with $ to help identify it as a selector cache later $('.list-item').click(function () { $photo = $photo || $('.photo'); $photo.hide(); }); </script>
I hope you will enjoy the tips while playing with JavaScript.I would like to have feedback from my blog readers. Your valuable feedback, question, or comments about this article are always welcome.

No comments:

Post a Comment