This code has the same effect as though the calls to capture
were calls to fn.
var queue = []; function capture() { queue.push(Array.prototype.slice.call(arguments, 0)); } function replay() { while (queue.length) fn.apply(null, queue.shift()); } function fn(a, b) { log(a + ' + ' + b + ' = ' + (a+b)); }
capture(1,2); capture(1,3); capture(10,20); replay();