Created
September 17, 2011 01:37
-
-
Save lfborjas/1223508 to your computer and use it in GitHub Desktop.
Javascript caching
This file contains hidden or 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
var god = { | |
a: 1, | |
b: 2 | |
}; | |
var templater = (function(){ | |
var cache = {}; | |
return function(name){ | |
if(cache[name]){ | |
console.log("cached"); | |
return cache[name]; | |
}else{ | |
cache[name] = god[name]; | |
return god[name]; | |
} | |
}; | |
})(); | |
console.log(templater('a')); | |
console.log(templater('a')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment