🕵️ SicherheitslückenHak5: Hackers Just Poisoned the Rust Supply Chain | Threat Wire(01.09.2026 um 14:00 Uhr)
🕵️ SicherheitslückenHak5: Hackers Found a Way Into Humanoid Robots | Threat Wire(04.09.2026 um 15:04 Uhr)
🔧 AI Nachrichten Bits und so #1021 (Passwort für Laufwerk)(31.08.2026 um 22:15 Uhr)
🔧 AI Nachrichten Bits und so #1022 (Wie Weißbier)(06.09.2026 um 20:39 Uhr)
🍏 iOS / Mac OSHue-App 6.0 ist da: das sind die Neuerungen(07.09.2026 um 17:21 Uhr)
🕵️ SicherheitslückenHak5: Hackers Just Poisoned the Rust Supply Chain | Threat Wire(01.09.2026 um 14:00 Uhr)
🕵️ SicherheitslückenHak5: Hackers Found a Way Into Humanoid Robots | Threat Wire(04.09.2026 um 15:04 Uhr)
🔧 AI Nachrichten Bits und so #1021 (Passwort für Laufwerk)(31.08.2026 um 22:15 Uhr)
🔧 AI Nachrichten Bits und so #1022 (Wie Weißbier)(06.09.2026 um 20:39 Uhr)
🍏 iOS / Mac OSHue-App 6.0 ist da: das sind die Neuerungen(07.09.2026 um 17:21 Uhr)

🔧 Programmierung 🕛 kürzlich 3 Min Lesezeit
0

Understanding JavaScript's Prototypal Inheritance - A Dev's Guide

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht

Hey fellow devs! After years of working with PHP's class-based inheritance, diving into JavaScript's prototypal inheritance felt like learning to write with my left hand. Today, I want to share what I've learned about this unique approach to inheritance that makes JavaScript special.






The Basics - What Makes It Different?



Unlike PHP or Java where we work with classes, JavaScript uses prototypes. Every object in JavaScript has an internal link to another object called its "prototype". Think of it as a fallback mechanism - when you try to access a property that doesn't exist in an object, JavaScript looks for it in the object's prototype.




CODE
const pet = {
makeSound() {
return "Some generic sound";
}
};

const cat = {
purr() {
return "Purrrr";
}
};

// Set pet as the prototype of cat
Object.setPrototypeOf(cat, pet);

// Now cat can use methods from pet
console.log(cat.makeSound()); // "Some generic sound"
console.log(cat.purr()); // "Purrrr"









The Proto Chain - It Goes Deeper



Here's where it gets interesting. Prototypes can have their own prototypes, forming what we call the "prototype chain". JavaScript will keep looking up this chain until it finds what it needs or hits a null prototype.




CODE
const animal = {
eat() {
return "Nom nom nom";
}
};

const pet = {
makeSound() {
return "Some generic sound";
}
};

const cat = {
purr() {
return "Purrrr";
}
};

Object.setPrototypeOf(pet, animal);
Object.setPrototypeOf(cat, pet);

// cat can now access methods from both pet and animal
console.log(cat.purr()); // "Purrrr"
console.log(cat.makeSound()); // "Some generic sound"
console.log(cat.eat()); // "Nom nom nom"









The Constructor Pattern - A More Familiar Approach



If you're coming from a class-based language like PHP, you might find the constructor pattern more familiar:




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

Animal.prototype.eat = function() {
return `${this.name} is eating`;
};

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

// Set up inheritance
Cat.prototype = Object.create(Animal.prototype);
Cat.prototype.constructor = Cat;

Cat.prototype.purr = function() {
return `${this.name} says purrrr`;
};

const felix = new Cat("Felix");
console.log(felix.eat()); // "Felix is eating"
console.log(felix.purr()); // "Felix says purrrr"









Modern JavaScript - Classes Under the Hood



ES6 introduced the class syntax, which might look familiar to PHP developers. But don't be fooled - it's just syntactic sugar over prototypal inheritance:




CODE
class Animal {
constructor(name) {
this.name = name;
}

eat() {
return `${this.name} is eating`;
}
}

class Cat extends Animal {
purr() {
return `${this.name} says purrrr`;
}
}

const felix = new Cat("Felix");









Pro Tips from the Trenches



After years of working with both PHP and JavaScript, here are some tips I've learned:




  1. Prefer composition over inheritance when possible

  2. Keep prototype chains shallow - deep chains can hurt performance

  3. Use class syntax for cleaner code, but understand prototypes for debugging

  4. Always set the constructor property when creating inheritance chains manually






Wrapping Up



Understanding prototypal inheritance might feel strange at first, especially if you're coming from PHP or Java. But once it clicks, you'll appreciate its flexibility and power. It's one of those JavaScript features that makes you think differently about object-oriented programming.



Have you encountered any interesting challenges with JavaScript inheritance? Drop a comment below - I'd love to hear your stories!

Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
Hackers Just Poisoned the Rust Supply Chain | Threat Wire
1 Quelle
Hackers Found a Way Into Humanoid Robots | Threat Wire
1 Quelle
Bits und so #1021 (Passwort für Laufwerk)
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Understanding JavaScript's Prototypal Inheritance - A Dev's Guide

Thematisch verwandte Begriffe: Understanding, JavaScripts, Prototypal, Inheritance · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...