DeveloperBreeze

البرمجة الكائنية Development Tutorials, Guides & Insights

Unlock 1+ expert-curated البرمجة الكائنية tutorials, real-world code snippets, and modern dev strategies. From fundamentals to advanced topics, boost your البرمجة الكائنية skills on DeveloperBreeze.

البرمجة الكائنية (OOP) في JavaScript: المفاهيم الأساسية والتطبيقات

Tutorial September 26, 2024
javascript

الوراثة هي مفهوم يسمح لك بإنشاء فئات جديدة بناءً على فئات موجودة. الفئة المشتقة (subclass) ترث الخصائص والأساليب من الفئة الأساسية (superclass).

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

    speak() {
        console.log(`${this.name} يصدر صوتًا.`);
    }
}

class Dog extends Animal {
    speak() {
        console.log(`${this.name} ينبح!`);
    }
}

const myDog = new Dog("بلاك");
myDog.speak();  // بلاك ينبح!