PS
Size: a a a
PS
AP
VK
function Counter(current: number) {
return () => ({
current,
next() {
return Counter(current + 1)();
}
})
}
const counter = Counter(1);
const c1 = counter(); console.log(c1.current); // 1
const c2 = c1.next(); console.log(c2.current); // 2
VK
const getCounter = () => {
function* inner (i) {
yield i+1; yield* inner(i+1)
}
const gen = (() => inner(0))()
return {
get value() { return gen.next().value }
}
}
PS
PS
const counter = getCounter();
console.log(counter.value);
console.log(counter.value);
S🛸
VK
const counter = getCounter();
console.log(counter.value);
console.log(counter.value);
VK
PS
S🛸
VK
VK
S🛸
PS
PS
S🛸
AD
KS
V