1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
function addAccumulations(f) { var a = f(); var b = f(); return a() + b(); } function loopingAccumulator() { var x = 0; return function () { for (var i = 0; i < 10; ++i) { ++x; } return x; } } var x = addAccumulations(loopingAccumulator); assertEq(x, 20);