TGViewer
JavaScript JavaScript @javascript · 31.1K subscribers
Post #2408 4.55K
CHALLENGE

function Animal(name) {
this.name = name;
}

Animal.prototype.speak = function() {
return `${this.name} makes a noise.`;
};

function Dog(name) {
Animal.call(this, name);
}

Dog.prototype = Object.create(Animal.prototype);
Dog.prototype.constructor = Dog;

Dog.prototype.speak = function() {
return `${this.name} barks.`;
};

const animal = new Animal('Rover');
const dog = new Dog('Rex');

console.log(dog instanceof Animal, dog.speak(), animal.speak(), Dog.prototype.isPrototypeOf(dog));
  • ❤ 8
  • 👍 1
  • 🔥 1
More from @javascript
  1. Oct 5, 2026🎵 Tonny Espeset has recreated the '80s hit Take on Me by A-ha in pure JavaScript (along w…
  2. Oct 5, 2026Post #3539
  3. Oct 5, 2026CHALLENGE class Base { static log = []; static { Base.log.push('base-block'); } static val…
  4. Oct 4, 2026👀 Size Limit: A JavaScript Performance Budgeting Tool Set a size or load-time budget for…
  5. Oct 4, 2026Post #3536
  6. Oct 4, 2026CHALLENGE const compose = (...fns) => fns.reduce((f, g) => (...args) => f(g(...args))); co…
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 →