I wanted an elegant way to implement memoizing. Here is what I came up with:
function memoize(fn) {
var cache = new WeakMap();
return function() {
if (!cache[arguments]) {
cache[arguments] = fn.call(this, arguments);
}
return cache[arguments];
}
}
It's quite nice, but the WeakMap is not well supported. Is there a better, yet clean way to do this?