Make _.memoize avoid using keyPrefix if passed a resolver function. [closes #330]

Former-commit-id: 97e3bb353d988c92eea394dfb496ebf7594ae25f
This commit is contained in:
John-David Dalton
2013-08-19 22:42:15 -07:00
parent 1901134601
commit a562126f2f
8 changed files with 103 additions and 33 deletions

View File

@@ -3781,6 +3781,20 @@
* var fibonacci = _.memoize(function(n) {
* return n < 2 ? n : fibonacci(n - 1) + fibonacci(n - 2);
* });
*
* var data = {
* 'moe': { 'name': 'moe', 'age': 40 },
* 'curly': { 'name': 'curly', 'age': 60 }
* };
*
* // modifying the result cache
* var stooge = _.memoize(function(name) { return data[name]; }, _.identity);
* stooge('curly');
* // => { 'name': 'curly', 'age': 60 }
*
* stooge.cache.curly.name = 'jerome';
* stooge('curly');
* // => { 'name': 'jerome', 'age': 60 }
*/
function memoize(func, resolver) {
var cache = {};