TGViewer
JavaScript JavaScript @javascript · 31K subscribers
Post #2200 5.24K
CHALLENGE

function Device(name) {
this.name = name;
this.isOn = false;
}

Device.prototype.turnOn = function() {
this.isOn = true;
return `${this.name} is now on`;
};

function Smartphone(name, model) {
Device.call(this, name);
this.model = model;
}

Smartphone.prototype = Object.create(Device.prototype);
Smartphone.prototype.constructor = Smartphone;

Smartphone.prototype.turnOn = function() {
const result = Device.prototype.turnOn.call(this);
return `${result} (model: ${this.model})`;
};

const myPhone = new Smartphone('iPhone', '13 Pro');
console.log(myPhone.turnOn());
  • 🔥 7
  • ❤ 2
  • 👍 2
  • 🤣 1
More from @javascript
  1. Oct 8, 2026Post #3546
  2. Oct 8, 2026CHALLENGE function tag(strings, ...values) { return strings.raw.join('|') + '::' + values.…
  3. Oct 7, 2026Post #3544
  4. Oct 7, 2026CHALLENGE const sym1 = Symbol('id'); const sym2 = Symbol('id'); const obj = { [sym1]: 'fir…
  5. Oct 6, 2026Post #3542
  6. Oct 6, 2026CHALLENGE async function* gen() { const x = yield 1; const y = yield x + 1; return x + y;…
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 →