Skip to content

Instantly share code, notes, and snippets.

@Kcko
Created June 19, 2019 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kcko/ac714f2bab7cb161a34f36b82346d0b9 to your computer and use it in GitHub Desktop.
Save Kcko/ac714f2bab7cb161a34f36b82346d0b9 to your computer and use it in GitHub Desktop.
function Selector_Cache() {
var collection = {};
function get_from_cache( selector ) {
if ( undefined === collection[ selector ] ) {
collection[ selector ] = $( selector );
}
return collection[ selector ];
}
return { get: get_from_cache };
}
var selectors = new Selector_Cache();
// Usage $( '#element' ) becomes
selectors.get( '#element' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment