function SelectorCache() {
var collection = {};
function getFromCache(selector) {
if (undefined === collection[selector]) {
collection[selector] = $(selector);
}
return collection[selector];
}
return {
get: getFromCache
};
}
var selectors = new SelectorCache();
// Usage $('#element') becomes:
selectors.get('#element');