Skip to content

Instantly share code, notes, and snippets.

@diegogurgel
Created November 8, 2013 11:59
Show Gist options
  • Save diegogurgel/7370018 to your computer and use it in GitHub Desktop.
Save diegogurgel/7370018 to your computer and use it in GitHub Desktop.
Untitled
<ul id="lista">
<li class="item">A</li>
<li class="item">B</li>
<li class="item">C</li>
<li class="item">D</li>
<li class="item">E</li>
</ul>
var S = function(tag){
if(!S.cache){
S.cache = {};
}
if(S.cache[tag]){
console.time("selectCache");
S.cache[tag] = S.cache[tag] ;
console.timeEnd("selectCache");
}
else{
console.time("selectTag");
S.cache[tag] = document.getElementsByTagName(tag);
console.timeEnd("selectTag");
}
return S.cache[tag];
};
S("li"); // Primeira seleçao, elementos ainda nao estao em cache
S("li"); // Segunda, com elementos em cache.
{"view":"split","fontsize":"100","seethrough":"","prefixfree":"1","page":"javascript"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment