Skip to main content
1 of 2

I just thought about this:

function memoize(fn) {
    var cache = {};
    return function() {
        var args = Array.prototype.slice(arguments).toString();
        if (!cache[args]) {
            cache[args] = fn.call(this, arguments);
        }
        return cache[args];
    }
}

It's very cross-browser. I can't think of any browser not supporting this.

But it does feel kind of ugly.