Created
April 17, 2017 06:25
-
-
Save qzm/bce41064c57f7ba691ad5981ef7e8cc1 to your computer and use it in GitHub Desktop.
将纯函数,做cache
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
function cached (fn) { | |
var cache = Object.create(null); | |
return (function cachedFn (str) { | |
var hit = cache[str]; | |
return hit || (cache[str] = fn(str)) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment