michael@0: function addAccumulations(f) { michael@0: var a = f(); michael@0: var b = f(); michael@0: return a() + b(); michael@0: } michael@0: michael@0: function loopingAccumulator() { michael@0: var x = 0; michael@0: return function () { michael@0: for (var i = 0; i < 10; ++i) { michael@0: ++x; michael@0: } michael@0: return x; michael@0: } michael@0: } michael@0: michael@0: function testLoopingAccumulator() { michael@0: var x = addAccumulations(loopingAccumulator); michael@0: return x; michael@0: } michael@0: assertEq(testLoopingAccumulator(), 20);