مرجع فئة JavaScript
فئات JavaScript
A class
هي نوع من الوظائف ، ولكن بدلاً من استخدام الكلمة الرئيسية
function
لبدءها ، نستخدم الكلمة الأساسية
class
، ويتم تعيين الخصائص داخل
constructor()
طريقة:
مثال
قم بإنشاء فئة سيارة ، ثم قم بإنشاء كائن يسمى "mycar" بناءً على فئة السيارة:
class Car { // Create a class
constructor(brand) { // Class constructor
this.carname = brand;
// Class body/properties
}
}
mycar = new Car("Ford"); // Create an object of Car
class
للحصول على برنامج تعليمي حول الفصول ، اقرأ البرنامج التعليمي لفصول JavaScript .
طرق الفصل
Method | Description |
---|---|
constructor() | A special method for creating and initializing objects created within a class |
كلمات فئة
Keyword | Description |
---|---|
extends | Extends a class (inherit) |
static | Defines a static method for a class |
super | Refers to the parent class |