memoize.js 395 B

12345678910111213
  1. var has = require('./has');
  2. exports = function(fn, hashFn) {
  3. var memoize = function(key) {
  4. var cache = memoize.cache;
  5. var address = '' + (hashFn ? hashFn.apply(this, arguments) : key);
  6. if (!has(cache, address)) cache[address] = fn.apply(this, arguments);
  7. return cache[address];
  8. };
  9. memoize.cache = {};
  10. return memoize;
  11. };
  12. module.exports = exports;