

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 5
click for more info
No active XP Potion
Accept a Quest
Login to submit answers
So... I tricked you a bit. Classes are actually a fairly new addition to JavaScript. See, they're not the underlying mechanism for inheritance - that's actually prototypes. Classes are just syntactic sugar for prototypes.
Every object in JavaScript has a prototype. When an object "inherits" from another object, it's really that its parent is marked as its "prototype". It's called prototypal inheritance. The built-in Object.create() method creates a new object with its prototype set to the given object.
const pureTitan = {
// (define a parent object / prototype)
name: "Eren's mom",
speak(msg) {
console.log("*titan noises*");
},
};
pureTitan.speak();
// *titan noises*
const beastTitan = Object.create(pureTitan); // (define a child)
console.log(beastTitan.name); // (accessing .name from pureTitan)
// Eren's mom
beastTitan.name = "Zeke";
beastTitan.speak = function () {
console.log(`${this.name} says, "I'm the Beast Titan"`);
};
beastTitan.speak();
// Zeke says, "I'm the Beast Titan"
Textio needs a new notification system that uses a new subclass of notification that can both:
Broadcast to all users: {MESSAGE}
Where "MESSAGE" is the given message string.
Focus Editor
Alt+Shift+]
Next Tab
Alt+Shift+[
Become a member to Submit
Become a member to Run
Become a member to view solution