From 95aca4b4d8fa62815d4bd412fff1a364f842814a Mon Sep 17 00:00:00 2001 From: Ryan Johnson Date: Thu, 29 Apr 2021 16:16:42 -0700 Subject: remove retired locales (#699) --- .../reference/classes/extends/index.html | 112 --------------------- 1 file changed, 112 deletions(-) delete mode 100644 files/bg/web/javascript/reference/classes/extends/index.html (limited to 'files/bg/web/javascript/reference/classes/extends') diff --git a/files/bg/web/javascript/reference/classes/extends/index.html b/files/bg/web/javascript/reference/classes/extends/index.html deleted file mode 100644 index 940e815d6c..0000000000 --- a/files/bg/web/javascript/reference/classes/extends/index.html +++ /dev/null @@ -1,112 +0,0 @@ ---- -title: extends -slug: Web/JavaScript/Reference/Classes/extends -tags: - - JavaScript наследяване - - Класове - - наследяване -translation_of: Web/JavaScript/Reference/Classes/extends ---- -
{{jsSidebar("Classes")}}
- -

Ключовата дума extends се използва в  декларацията на класове или класовите изрази за създаване на клас, който е дете на друг клас.

- -
{{EmbedInteractiveExample("pages/js/classes-extends.html", "taller")}}
- - - -

Синтаксис

- -
class ChildClass extends ParentClass { ... }
- -

Описание

- -

Ключовата дума extends може да бъде използвана като подклас на потребителски класове, както и за вградени обекти.

- -

Прототипът (.prototype) на разширението трябва да е  {{jsxref("Object")}} или {{jsxref("null")}}.

- -

Примери

- -

Използване на  extends

- -

Първият пример създава клас, наречен Square от клас, наречен Polygon (Square класът наследява клас Polygon ). Този пример е взет от това демо на живо (източник).

- -
class Square extends Polygon {
-  constructor(length) {
-    // Here, it calls the parent class' constructor with lengths
-    // provided for the Polygon's width and height
-    super(length, length);
-    // Note: In derived classes, super() must be called before you
-    // can use 'this'. Leaving this out will cause a reference error.
-    this.name = 'Square';
-  }
-
-  get area() {
-    return this.height * this.width;
-  }
-}
- -

Използване на  extends с вградени обекти

- -

Този пример разширява вграденият {{jsxref("Date")}} обект. Този пример е взет от това демо на живо (източник).

- -
class myDate extends Date {
-  constructor() {
-    super();
-  }
-
-  getFormattedDate() {
-    var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
-    return this.getDate() + '-' + months[this.getMonth()] + '-' + this.getFullYear();
-  }
-}
- -

Наследяване на  null

- -

Наследяване от {{jsxref("null")}} работи както при нормалните класове, eс изключение на това , че обектът на прототипа не наследява от {{jsxref("Object.prototype")}}.

- -
class nullExtends extends null {
-  constructor() {}
-}
-
-Object.getPrototypeOf(nullExtends); // Function.prototype
-Object.getPrototypeOf(nullExtends.prototype) // null
-
-new nullExtends(); //ReferenceError: this is not defined
-
- -

Спецификации

- - - - - - - - - - - - - - - - - - - -
СпецификацииСтатусКоментар
{{SpecName('ES2015', '#sec-class-definitions', 'extends')}}{{Spec2('ES2015')}}Initial definition.
{{SpecName('ESDraft', '#sec-class-definitions', 'extends')}}{{Spec2('ESDraft')}} 
- -

Съвместимост с браузъра

- - - -

{{Compat("javascript.classes.extends")}}

- -

Вижте още

- - -- cgit v1.2.3-54-g00ecf