GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

No menu could be recovered. Follow the blue links in the page.

This view

  • Original page
  • New address

GeezerVison is showing uz.javascript.info — Namuna yaratishda xato

  • Qo'llanma
  • JavaScript dasturlash tili
  • Klasslar
  • Klass meros olish (Class inheritance)
darsga qaytish

Namuna yaratishda xato

Rabbit kengaytirilgan Animal kodi.

Afsuski, Rabbit obyektlarini yaratish mumkin emas. Nima bo’ldi? Tuzating.

class Animal {

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

}

class Rabbit extends Animal {
  constructor(name) {
    this.name = name;
    this.created = Date.now();
  }
}

let rabbit = new Rabbit("White Rabbit"); // Error: this is not defined
alert(rabbit.name);

Buning sababi, bola konstruktor super() ni chaqirishi kerak.

Mana tuzatilgan kod:

class Animal {

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

}

class Rabbit extends Animal {
  constructor(name) {
    super(name);
    this.created = Date.now();
  }
}

let rabbit = new Rabbit("White Rabbit"); //yaxshi hozir
alert(rabbit.name); // White Rabbit
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.