Если я протестирую этот код в консоли Chrome, я могу увидеть в объекте [[Scopes]], что первый элемент называется Closure, и он имеет правильные имена и значения закрытий счетчиков. Я не могу найти способ заставить эту работу работать с FireFox или найти другую альтернативу.
const counter = (function(increment, offset) {
let value = offset - increment;
let firstValue = offset;
return function() {
firstValue; // only here for the sake of this demo
value += increment;
return value;
}
})(2, 10);
console.dir(counter); // increment: 2, value: 8, firstValue: 10
counter(); // returns 10
console.dir(counter); // increment: 2, value: 10, firstValue: 10
counter(); // returns 12
console.dir(counter); // increment: 2, value: 12, firstValue: 10