class Car{
constaractor(make,model,year){
this.make=make;
this.model=model;
this.year=year;
}
run(){
return 'speed up to 200'
}
}
class IranCar extends Car {
constaractor(make,model,year,color){
super(make,model,year)
this.color=color;
}
fly(){
return 'car is flying';
}
go(){
this.run();
}
}
let car1=new IranCar("ford","mustang",2000,'red');
console.log(car1);
خروجی:
Irancar{make:"foard",model:"mustang",year:2000,color:"red"}
نکته:
super یک تابع سراسری یا کیبورد رزرو شده است
که به کلاس پدر اشاره میکنه
در پرانتز هم انگار constaractor پدر داره صدا زده میشه و میتونیم به اون مقادیر موجود در پدر دسترسی داشته باشیم
درباره این سایت