TGViewer
JavaScript JavaScript @javascript · 31.1K subscribers
Post #3529 548
CHALLENGE

class Counter {
#count = 0;
static #instances = 0;
constructor() { Counter.#instances++; }
#increment() { this.#count++; }
incrementAndGet() {
this.#increment();
return this.#count;
}
static get total() { return Counter.#instances; }
}

class SpecialCounter extends Counter {
incrementAndGet() {
return super.incrementAndGet() * 2;
}
}

const c1 = new Counter();
const c2 = new SpecialCounter();
console.log(`${c1.incrementAndGet()} ${c2.incrementAndGet()} ${Counter.total}`);
More from @javascript
  1. Oct 1, 2026Post #3530
  2. Sep 30, 2026Post #3528
  3. Sep 30, 2026CHALLENGE const message = 'a😀bc'; const codePoints = [...message]; const combined = { raw…
  4. Sep 29, 2026Post #3526
  5. Sep 29, 2026CHALLENGE const order = []; order.push('start'); setTimeout(() => { order.push('timeout');…
  6. Sep 28, 2026Post #3524
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →