Joined July 2012
·
Posted to
jQuery DOM cache object
over 1 year
ago
How about something like:
$C = (function($){
var DOMCACHESTORE = {};
return function(selector, force) {
if (DOMCACHESTORE[selector] !== undefined && !force) {
return DOMCACHESTORE[selector];
}
DOMCACHESTORE[selector] = $(selector);
return DOMCACHESTORE[selector];
}
})($);
Then you can replace all your "$('h1')" with "$C('h1')", which is a lot less to type than "DOMCACHE.get('h2')".
Achievements
76 Karma
0 Total ProTip Views
Nephila Komaci
Have at least one original repos where PHP is the dominant language
Walrus
The walrus is no stranger to variety. Use at least 4 different languages throughout all your repos
Forked
Have a project valued enough to be forked by someone else
Charity
Fork and commit to someone's open source project in need
Python 3
Have at least three original repos where Python is the dominant language
Python
Would you expect anything less? Have at least one original repo where Python is the dominant language
Raven
Have at least one original repo where some form of shell script is the dominant language
Don't forget about Silver Searcher:
sudo apt-get install silversearcher-ag
It lets you do
ag foo
, which is roughly equivalent tofind -type f|xargs grep foo
, but executes way faster.