var counter = new Counter(); var numbers = [1, 2, 3]; var sum = 0; numbers.forEach(function (e) { sum += e; this.increase(); }, counter); console.log(sum); // 6 console.log(counter.current()); // 3 Code language: JavaScript (javascript)