Last active
October 10, 2015 13:58
-
-
Save gerard-morera/ac82872a5d9e306d2326 to your computer and use it in GitHub Desktop.
This file contains 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
“Here is a simplified implementation, though there are plenty of more robust versions available. | |
var memoize = function(f) { | |
var cache = {}; | |
return function() { | |
var arg_str = JSON.stringify(arguments); | |
cache[arg_str] = cache[arg_str] || f.apply(f, arguments); | |
return cache[arg_str]; | |
}; | |
}; | |
Something to note is that you can transform some impure functions into pure ones by delaying evaluation: | |
var pureHttpCall = memoize(function(url, params){ | |
return function() { return $.getJSON(url, params); } | |
});” | |
Excerpt From: drboolean. “mostly-adequate-guide.” iBooks. https://itunes.apple.com/WebObjects/MZStore.woa/wa/viewBook?id=828C74EE750961AEB99EE55C5B4B538A |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment