Created
January 7, 2014 16:37
-
-
Save mikemclin/8302090 to your computer and use it in GitHub Desktop.
Module method for caching jQuery selectors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(window, document, $, undefined){ | |
var self = $.Module = {}; | |
self.init = function() { | |
this.cache(); | |
}; | |
self.cache = function() { | |
var _storage = {}; | |
self.cache = { | |
$: function(selector, clear) { | |
clear = ( typeof clear !== 'undefined' ) ? clear : false; | |
if ( typeof _storage[selector] !== 'undefined' && ! clear ) { | |
return _storage[selector]; | |
} else { | |
return _storage[selector] = $(selector); | |
} | |
}, | |
get: function() { | |
return _storage; | |
}, | |
flush: function() { | |
_storage = {}; | |
} | |
}; | |
}; | |
self.init(); | |
}(this, this.document, this.jQuery)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment