JavaScript

extends & super (JS)

Në shqip: Trashëgimia në JavaScript

ShpjegimiSQ

Me class Qen extends Kafshe, klasa e re trashëgon gjithçka nga prindi. super(...) thërret konstruktorin e prindit dhe super.metoda() versionin e tij të metodës.

EnglishEN

With class Dog extends Animal, the new class inherits everything from the parent. super(...) calls the parent's constructor and super.method() its version of the method.

Si ta mendosh

Si fëmija që trashëgon mbiemrin dhe disa zakone nga prindërit.

Lexoje në anglisht

Like a child inheriting the surname and some habits from their parents.

Shembull kodijavascript

class Kafshe { constructor(emri) { this.emri = emri; } }
class Qen extends Kafshe {
  constructor(emri) { super(emri); }
  leh() { return `${this.emri}: Ham!`; }
}

Terma të lidhur