1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#!/usr/bin/env node "use strict"; /** * @param {number} n * @return {Function} counter */ var createCounter = function (n) { var count = n; return function () { return count++; }; }; const counter = createCounter(10); console.log(counter()); // 10 console.log(counter()); // 11 console.log(counter()); // 12