TGViewer
JavaScript JavaScript @javascript · 31.1K subscribers
Post #2888 3.94K
CHALLENGE

class Vehicle {
#engine = 'V6';
static count = 0;

constructor(type) {
this.type = type;
Vehicle.count++;
}

static getCount() {
return this.count;
}

get info() {
return `${this.type} with ${this.#engine}`;
}
}

class Car extends Vehicle {
static count = 0;

constructor(brand) {
super('car');
this.brand = brand;
Car.count++;
}
}

const tesla = new Car('Tesla');
const ford = new Car('Ford');
console.log(Vehicle.getCount());
console.log(Car.getCount());
console.log(tesla.info);
  • ❤ 3
  • 👍 2
  • 🔥 1
More from @javascript
  1. Sep 29, 2026Post #3526
  2. Sep 29, 2026CHALLENGE const order = []; order.push('start'); setTimeout(() => { order.push('timeout');…
  3. Sep 28, 2026Post #3524
  4. Sep 28, 2026CHALLENGE let order = []; function a() { try { return 'try'; } finally { order.push('a-fin…
  5. Sep 27, 2026Post #3522
  6. Sep 27, 2026CHALLENGE class Base { value = 10; getValue = () => this.value; constructor() { this.value…
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 →