Pull to refresh

Кэширование селекторов для jQuery. Плагин

Reading time1 min
Views3.7K
Простой плагин для jQuery, позволяющий закэшировать работу селекторов.
По наводке tenshi в камментах к habrahabr.ru/blogs/javascript/63119

(function($) {
 
 var selectorCache = [];
             
 $.cache = {

  get : function(selector) {
   return selectorCache[selector] || (selectorCache[selector] = $(selector)); 
  },
  
  clear: function(selector) {
   selector == null ? selectorCache = [] : selectorCache[selector] = null;
  }
 }
 
})(jQuery);

* This source code was highlighted with Source Code Highlighter.

Использовать примерно так:
// Before
$('#some .css .selector').some().action();

// After
$.cache.get('#some .css .selector').some().action();


* This source code was highlighted with Source Code Highlighter.
Tags:
Hubs:
+9
Comments32

Articles