1. Class declaration
class is sugar over the prototype chain; methods live on Animal.prototype.
class Animal {Typorithm · medium
Step 1 of 8 · intro card
Objects & this
class is syntax over the prototype chain: methods live on the prototype and are shared by all instances. extends links a subclass to its parent's prototype, and super calls the parent's constructor or methods.
A class declaration defines a constructor plus methods. The methods are placed on Animal.prototype, so every instance shares one copy rather than getting its own.
Looking up a property walks the prototype chain: the instance first, then Animal.prototype, then Object.prototype — class syntax just makes this readable.
extends sets the subclass's prototype to inherit from the parent, so a Dog instance can use Animal's methods directly.
Inside a subclass, super.method() calls the parent's version (and super(...) in a constructor runs the parent constructor first), letting you extend behaviour instead of copy-pasting it.
class is sugar over the prototype chain.
Methods live on the prototype, shared by all instances.
extends links a subclass to its parent.
super calls the parent constructor or method.
class Animal {
constructor(name) {
this.name = name;
}
speak() {
return this.name + " makes a sound";
}
}
class Dog extends Animal {
speak() {
return super.speak() + " (woof)";
}
}Connect each part of the code to the concept before you type.
class is sugar over the prototype chain; methods live on Animal.prototype.
class Animal {constructor runs when you call new Animal(...) to initialise the instance.
constructor(name) {speak is stored once on the prototype and shared by every instance.
speak() {
return this.name + " makes a sound";
}extends links Dog.prototype to Animal.prototype, inheriting its methods.
class Dog extends Animal {super.speak() invokes the parent's method, letting Dog extend rather than fully replace it.
super.speak()Read the concept map and follow the code breakdown.
Type the implementation, repair mistakes and work through every recall exercise.
Use the final check without hints; revisit weak concepts in short practice sessions.