Created
November 12, 2009 06:48
-
-
Save anfedorov/232666 to your computer and use it in GitHub Desktop.
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
goog.memoize = function(f, opt_serializer) { | |
var functionHash = goog.getHashCode(f); | |
var serializer = opt_serializer || goog.memoize.simpleSerializer; | |
return function() { | |
// Maps the serialized list of args to the corresponding return value. | |
var cache = this[goog.memoize.CACHE_PROPERTY_]; | |
if (!cache) { | |
cache = this[goog.memoize.CACHE_PROPERTY_] = {}; | |
} | |
var key = serializer(functionHash, arguments); | |
if (!(key in cache)) { | |
cache[key] = f.apply(this, arguments); | |
} | |
return cache[key]; | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment