krambuhl/Kondico

View on GitHub
source/memoize.js

Summary

Maintainability
A
0 mins
Test Coverage
function memoize(method, hasher, options) {
  var cache = {};
  
  if (typeof hasher !== 'function') {
    hasher = function() { return arguments[0]; };
  }

  return function() {
    var hash = hasher.apply(this, arguments);
    if (cache[hash] === undefined) {
      cache[hash] = method.apply(this, arguments);
    } 
    return cache[hash];
  };
}