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/constructor/index.html | 130 ------- .../reference/classes/extends/index.html | 112 ------ .../bg/web/javascript/reference/classes/index.html | 431 --------------------- .../javascript/reference/classes/static/index.html | 135 ------- 4 files changed, 808 deletions(-) delete mode 100644 files/bg/web/javascript/reference/classes/constructor/index.html delete mode 100644 files/bg/web/javascript/reference/classes/extends/index.html delete mode 100644 files/bg/web/javascript/reference/classes/index.html delete mode 100644 files/bg/web/javascript/reference/classes/static/index.html (limited to 'files/bg/web/javascript/reference/classes') diff --git a/files/bg/web/javascript/reference/classes/constructor/index.html b/files/bg/web/javascript/reference/classes/constructor/index.html deleted file mode 100644 index 4d3971672e..0000000000 --- a/files/bg/web/javascript/reference/classes/constructor/index.html +++ /dev/null @@ -1,130 +0,0 @@ ---- -title: constructor -slug: Web/JavaScript/Reference/Classes/constructor -tags: - - Класове - - Конструктор -translation_of: Web/JavaScript/Reference/Classes/constructor ---- -
{{jsSidebar("Classes")}}
- -

Методът constructor е специален метод за създаване и инициализиране на обект , създаден в рамките класът (class).

- -
{{EmbedInteractiveExample("pages/js/classes-constructor.html")}}
- - - -

Синтаксис

- -
constructor([arguments]) { ... }
- -

Описание

- -

Може да има само един специален метод с име "constructor" в даден клас (class). Ако има повече от един метод с името constructor в класът си , ще се появи грешка   {{jsxref("SyntaxError")}}.

- -

Конструктора (constructor) може да използва ключовата дума super за да извика конструктора на родителския клас.

- -

Ако не посочите метода конструктор, ще се използва конструктор по подразбиране

- -

Примери

- -

Използване на метода  constructor

- -

Този примерен код е взет от  classes sample (демо на живо).

- -
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;
-  }
-
-  set area(value) {
-    this.area = value;
-  }
-}
- -

Друг пример

- -

Разгледайте този код :

- -
class Polygon {
-    constructor() {
-        this.name = "Polygon";
-    }
-}
-
-class Square extends Polygon {
-    constructor() {
-        super();
-    }
-}
-
-class Rectangle {}
-
-Object.setPrototypeOf(Square.prototype, Rectangle.prototype);
-
-console.log(Object.getPrototypeOf(Square.prototype) === Polygon.prototype); //false
-console.log(Object.getPrototypeOf(Square.prototype) === Rectangle.prototype); //true
-
-let newInstance = new Square();
-console.log(newInstance.name); //Polygon
- -

Тук прототипа на класът Square се променя, но все пак конструктора на предишния базов клас Polygon се извиква, когато се създава нова инстанция(екземлпяр) от класът Square. Това е така , защото в класът Squre използваме ключовата дума super, извиквайки конструктора на родителският клас Polygon .

- -

Конструктор по подразбиране

- -

Както е посочено,ако не посочите метод конструктор, ще се използва  конструктор по подразбиране . За базовите класове , конструктора по подразбиране е :

- -
constructor() {}
-
- -

За производни класове, конструктора по подразбиране е :

- -
constructor(...args) {
-  super(...args);
-}
- -

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

- - - - - - - - - - - - - - - - - - - -
SpecificationStatusComment
{{SpecName('ES2015', '#sec-static-semantics-constructormethod', 'Constructor Method')}}{{Spec2('ES2015')}}Initial definition.
{{SpecName('ESDraft', '#sec-static-semantics-constructormethod', 'Constructor Method')}}{{Spec2('ESDraft')}} 
- -

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

- - - -

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

- -

Въжте също

- - 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")}}

- -

Вижте още

- - diff --git a/files/bg/web/javascript/reference/classes/index.html b/files/bg/web/javascript/reference/classes/index.html deleted file mode 100644 index dc88fc8548..0000000000 --- a/files/bg/web/javascript/reference/classes/index.html +++ /dev/null @@ -1,431 +0,0 @@ ---- -title: Classes -slug: Web/JavaScript/Reference/Classes -tags: - - Classes - - Constructors - - ECMAScript 2015 - - Inheritance - - Intermediate - - JavaScript - - NeedsTranslation - - TopicStub -translation_of: Web/JavaScript/Reference/Classes ---- -
{{JsSidebar("Classes")}}
- -

JavaScript classes, introduced in ECMAScript 2015, are primarily syntactical sugar over JavaScript's existing prototype-based inheritance. The class syntax does not introduce a new object-oriented inheritance model to JavaScript.

- -

Defining classes

- -

Classes are in fact "special functions", and just as you can define function expressions and function declarations, the class syntax has two components: class expressions and class declarations.

- -

Class declarations

- -

One way to define a class is using a class declaration. To declare a class, you use the class keyword with the name of the class ("Rectangle" here).

- -
class Rectangle {
-  constructor(height, width) {
-    this.height = height;
-    this.width = width;
-  }
-}
- -

Hoisting

- -

An important difference between function declarations and class declarations is that function declarations are {{Glossary("Hoisting", "hoisted")}} and class declarations are not. You first need to declare your class and then access it, otherwise code like the following will throw a {{jsxref("ReferenceError")}}:

- -
const p = new Rectangle(); // ReferenceError
-
-class Rectangle {}
-
- -

Class expressions

- -

A class expression is another way to define a class. Class expressions can be named or unnamed. The name given to a named class expression is local to the class's body. (it can be retrieved through the class's (not an instance's) {{jsxref("Function.name", "name")}} property, though).

- -
// unnamed
-let Rectangle = class {
-  constructor(height, width) {
-    this.height = height;
-    this.width = width;
-  }
-};
-console.log(Rectangle.name);
-// output: "Rectangle"
-
-// named
-let Rectangle = class Rectangle2 {
-  constructor(height, width) {
-    this.height = height;
-    this.width = width;
-  }
-};
-console.log(Rectangle.name);
-// output: "Rectangle2"
-
- -
-

Note: Class expressions are subject to the same hoisting restrictions as described in the {{anch("Class declarations")}} section.

-
- -

Class body and method definitions

- -

The body of a class is the part that is in curly brackets {}. This is where you define class members, such as methods or constructor.

- -

Strict mode

- -

The body of a class is executed in strict mode, i.e., code written here is subject to stricter syntax for increased performance, some otherwise silent errors will be thrown, and certain keywords are reserved for future versions of ECMAScript.

- -

Constructor

- -

The constructor method is a special method for creating and initializing an object created with a class. There can only be one special method with the name "constructor" in a class. A {{jsxref("SyntaxError")}} will be thrown if the class contains more than one occurrence of a constructor method.

- -

A constructor can use the super keyword to call the constructor of the super class.

- -

Prototype methods

- -

See also method definitions.

- -
class Rectangle {
-  constructor(height, width) {
-    this.height = height;
-    this.width = width;
-  }
-  // Getter
-  get area() {
-    return this.calcArea();
-  }
-  // Method
-  calcArea() {
-    return this.height * this.width;
-  }
-}
-
-const square = new Rectangle(10, 10);
-
-console.log(square.area); // 100
- -

Static methods

- -

The static keyword defines a static method for a class. Static methods are called without instantiating their class and cannot be called through a class instance. Static methods are often used to create utility functions for an application.

- -
class Point {
-  constructor(x, y) {
-    this.x = x;
-    this.y = y;
-  }
-
-  static distance(a, b) {
-    const dx = a.x - b.x;
-    const dy = a.y - b.y;
-
-    return Math.hypot(dx, dy);
-  }
-}
-
-const p1 = new Point(5, 5);
-const p2 = new Point(10, 10);
-
-console.log(Point.distance(p1, p2)); // 7.0710678118654755
- -

Boxing with prototype and static methods

- -

When a static or prototype method is called without a value for this, the this value will be undefined inside the method. This behavior will be the same even if the "use strict" directive isn't present, because code within the class body's syntactic boundary is always executed in strict mode.

- -
class Animal {
-  speak() {
-    return this;
-  }
-  static eat() {
-    return this;
-  }
-}
-
-let obj = new Animal();
-obj.speak(); // Animal {}
-let speak = obj.speak;
-speak(); // undefined
-
-Animal.eat() // class Animal
-let eat = Animal.eat;
-eat(); // undefined
- -

If the above is written using traditional function-based syntax, then autoboxing in method calls will happen in non–strict mode based on the initial this value. If the initial value is undefinedthis will be set to the global object.

- -

Autoboxing will not happen in strict mode, the this value remains as passed.

- -
function Animal() { }
-
-Animal.prototype.speak = function() {
-  return this;
-}
-
-Animal.eat = function() {
-  return this;
-}
-
-let obj = new Animal();
-let speak = obj.speak;
-speak(); // global object
-
-let eat = Animal.eat;
-eat(); // global object
-
- -

Instance properties

- -

Instance properties must be defined inside of class methods:

- -
class Rectangle {
-  constructor(height, width) {
-    this.height = height;
-    this.width = width;
-  }
-}
- -

Static class-side properties and prototype data properties must be defined outside of the ClassBody declaration:

- -
Rectangle.staticWidth = 20;
-Rectangle.prototype.prototypeWidth = 25;
-
- -

Field declarations

- -
-

Public and private field declarations are an experimental feature (stage 3) proposed at TC39, the JavaScript standards committee. Support in browsers is limited, but the feature can be used through a build step with systems like Babel.

-
- -

Public field declarations

- -

With the JavaScript field declaration syntax, the above example can be written as:

- -
class Rectangle {
-  height = 0;
-  width;
-  constructor(height, width) {
-    this.height = height;
-    this.width = width;
-  }
-}
-
- -

By declaring fields up-front, class definitions become more self-documenting, and the fields are always present.

- -

As seen above, the fields can be declared with or without a default value.

- -

Private field declarations

- -

Using private fields, the definition can be refined as below.

- -
class Rectangle {
-  #height = 0;
-  #width;
-  constructor(height, width) {
-    this.#height = height;
-    this.#width = width;
-  }
-}
-
- -

It's an error to reference private fields from outside of the class; they can only be read or written within the class body. By defining things which are not visible outside of the class, you ensure that your classes' users can't depend on internals, which may change version to version.

- -
-

Private fields can only be declared up-front in a field declaration.

-
- -

Private fields cannot be created later through assigning to them, the way that normal properties can.

- -

 

- -

Sub classing with extends

- -

The extends keyword is used in class declarations or class expressions to create a class as a child of another class.

- -
class Animal {
-  constructor(name) {
-    this.name = name;
-  }
-
-  speak() {
-    console.log(this.name + ' makes a noise.');
-  }
-}
-
-class Dog extends Animal {
-  constructor(name) {
-    super(name); // call the super class constructor and pass in the name parameter
-  }
-
-  speak() {
-    console.log(this.name + ' barks.');
-  }
-}
-
-let d = new Dog('Mitzie');
-d.speak(); // Mitzie barks.
-
- -

If there is a constructor present in the subclass, it needs to first call super() before using "this".

- -

One may also extend traditional function-based "classes":

- -
function Animal (name) {
-  this.name = name;
-}
-
-Animal.prototype.speak = function () {
-  console.log(this.name + ' makes a noise.');
-}
-
-class Dog extends Animal {
-  speak() {
-    console.log(this.name + ' barks.');
-  }
-}
-
-let d = new Dog('Mitzie');
-d.speak(); // Mitzie barks.
-
- -

Note that classes cannot extend regular (non-constructible) objects. If you want to inherit from a regular object, you can instead use {{jsxref("Object.setPrototypeOf()")}}:

- -
const Animal = {
-  speak() {
-    console.log(this.name + ' makes a noise.');
-  }
-};
-
-class Dog {
-  constructor(name) {
-    this.name = name;
-  }
-}
-
-// If you do not do this you will get a TypeError when you invoke speak
-Object.setPrototypeOf(Dog.prototype, Animal);
-
-let d = new Dog('Mitzie');
-d.speak(); // Mitzie makes a noise.
-
- -

Species

- -

You might want to return {{jsxref("Array")}} objects in your derived array class MyArray. The species pattern lets you override default constructors.

- -

For example, when using methods such as {{jsxref("Array.map", "map()")}} that returns the default constructor, you want these methods to return a parent Array object, instead of the MyArray object. The {{jsxref("Symbol.species")}} symbol lets you do this:

- -
class MyArray extends Array {
-  // Overwrite species to the parent Array constructor
-  static get [Symbol.species]() { return Array; }
-}
-
-let a = new MyArray(1,2,3);
-let mapped = a.map(x => x * x);
-
-console.log(mapped instanceof MyArray); // false
-console.log(mapped instanceof Array);   // true
-
- -

Super class calls with super

- -

The super keyword is used to call corresponding methods of super class. This is one advantage over prototype-based inheritance.

- -
class Cat {
-  constructor(name) {
-    this.name = name;
-  }
-
-  speak() {
-    console.log(`${this.name} makes a noise.`);
-  }
-}
-
-class Lion extends Cat {
-  speak() {
-    super.speak();
-    console.log(`${this.name} roars.`);
-  }
-}
-
-let l = new Lion('Fuzzy');
-l.speak();
-// Fuzzy makes a noise.
-// Fuzzy roars.
-
- -

Mix-ins

- -

Abstract subclasses or mix-ins are templates for classes. An ECMAScript class can only have a single superclass, so multiple inheritance from tooling classes, for example, is not possible. The functionality must be provided by the superclass.

- -

A function with a superclass as input and a subclass extending that superclass as output can be used to implement mix-ins in ECMAScript:

- -
let calculatorMixin = Base => class extends Base {
-  calc() { }
-};
-
-let randomizerMixin = Base => class extends Base {
-  randomize() { }
-};
-
- -

A class that uses these mix-ins can then be written like this:

- -
class Foo { }
-class Bar extends calculatorMixin(randomizerMixin(Foo)) { }
- -

Specifications

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SpecificationStatusComment
{{SpecName('ES2015', '#sec-class-definitions', 'Class definitions')}}{{Spec2('ES2015')}}Initial definition.
{{SpecName('ES2016', '#sec-class-definitions', 'Class definitions')}}{{Spec2('ES2016')}} 
{{SpecName('ES2017', '#sec-class-definitions', 'Class definitions')}}{{Spec2('ES2017')}} 
{{SpecName('ESDraft', '#sec-class-definitions', 'Class definitions')}}{{Spec2('ESDraft')}} 
- -

Browser compatibility

- - - -

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

- -

Running in Scratchpad

- -

A class can't be redefined. If you're playing with code in Scratchpad (Firefox menu Tools > Web Developer > Scratchpad) and you 'Run' a definition of a class with the same name twice, you'll get a confusing SyntaxError: redeclaration of let <class-name>.

- -

To re-run a definition, use Scratchpad's menu Execute > Reload and Run.
- Please vote for bug #1428672.

- -

See also

- - diff --git a/files/bg/web/javascript/reference/classes/static/index.html b/files/bg/web/javascript/reference/classes/static/index.html deleted file mode 100644 index 971bf40345..0000000000 --- a/files/bg/web/javascript/reference/classes/static/index.html +++ /dev/null @@ -1,135 +0,0 @@ ---- -title: static -slug: Web/JavaScript/Reference/Classes/static -tags: - - Класове - - Статичен - - статичен метод -translation_of: Web/JavaScript/Reference/Classes/static ---- -
{{jsSidebar("Classes")}}
- -

Ключовата дума static дефинира статичен метод за клас. Static methods aren't called on instances of the class. Instead, they're called on the class itself. Това често са помощни функции, като например функции за създаване или клониране на обекти.

- -
{{EmbedInteractiveExample("pages/js/classes-static.html")}}
- - - -

Синтаксис

- -
static methodName() { ... }
- -

Описание

- -

Статичните методи се правят директно в класът и не могат да се извикват като инстанции на клас.

- -

Извикване на статичен метод

- -

От друг статичен метод

- -

За да извикате статичен метод в рамките на друг статичен метод от същия клас, може да използвате ключовата дума this.

- -
class StaticMethodCall {
-  static staticMethod() {
-    return 'Static method has been called';
-  }
-  static anotherStaticMethod() {
-    return this.staticMethod() + ' from another static method';
-  }
-}
-StaticMethodCall.staticMethod();
-// 'Static method has been called'
-
-StaticMethodCall.anotherStaticMethod();
-// 'Static method has been called from another static method'
- -

От конструктора на клас и други методи

- -

Статичните методи не са пряко достъпни, когато се използва ключовата дума this от нестатични методи. Трябва да ги извикате, използвайки името на класа: CLASSNAME.STATIC_METHOD_NAME() или да извикате метода като собственост на constructorthis.constructor.STATIC_METHOD_NAME().

- -
class StaticMethodCall {
-  constructor() {
-    console.log(StaticMethodCall.staticMethod());
-    // 'static method has been called.'
-
-    console.log(this.constructor.staticMethod());
-    // 'static method has been called.'
-  }
-
-  static staticMethod() {
-    return 'static method has been called.';
-  }
-}
- -

Примери

- -

Следният пример показва няколко неща:

- -
    -
  1. Как статичните методи се изпълняват в класът.
  2. -
  3. Това , че клас със статичен член може да бъде под-класиран.
  4. -
  5. Как статичният метод може и не може да бъде извикан.
  6. -
- -
class Triple {
-  static triple(n) {
-    if (n === undefined) {
-      n = 1;
-    }
-    return n * 3;
-  }
-}
-
-class BiggerTriple extends Triple {
-  static triple(n) {
-    return super.triple(n) * super.triple(n);
-  }
-}
-
-console.log(Triple.triple());        // 3
-console.log(Triple.triple(6));       // 18
-
-var tp = new Triple();
-
-console.log(BiggerTriple.triple(3));
-// 81 (not affected by parent's instantiation)
-
-console.log(tp.triple());
-// 'tp.triple is not a function'.
-
- -

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

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

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

- - - -

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

- -

Вижте още

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