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 | 172 --------- .../web/javascript/reference/classes/index.html | 383 --------------------- .../javascript/reference/classes/static/index.html | 179 ---------- files/sv-se/web/javascript/reference/index.html | 51 --- 4 files changed, 785 deletions(-) delete mode 100644 files/sv-se/web/javascript/reference/classes/extends/index.html delete mode 100644 files/sv-se/web/javascript/reference/classes/index.html delete mode 100644 files/sv-se/web/javascript/reference/classes/static/index.html delete mode 100644 files/sv-se/web/javascript/reference/index.html (limited to 'files/sv-se/web/javascript/reference') diff --git a/files/sv-se/web/javascript/reference/classes/extends/index.html b/files/sv-se/web/javascript/reference/classes/extends/index.html deleted file mode 100644 index c72398e470..0000000000 --- a/files/sv-se/web/javascript/reference/classes/extends/index.html +++ /dev/null @@ -1,172 +0,0 @@ ---- -title: extends -slug: Web/JavaScript/Reference/Classes/extends -tags: - - ECMAScript 2015 - - JavaScript - - Klasser -translation_of: Web/JavaScript/Reference/Classes/extends ---- -
{{jsSidebar("Classes")}}
- -

Nyckelorder extends används i klassdeklarationer eller klassuttryck för att skapa en klass som är barn till en annan klass.

- -

Syntax

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

Beskrivning

- -

Nyckelordet extends kan användas för att subklassa anpassade klasser såväl som inbyggda objekt.

- -

.prototype vid användning av extends måste vara en {{jsxref("Object")}} eller {{jsxref("null")}}.

- -

Exempel

- -

Använda extends

- -

Första exemplet skapar en klass som heter Square från en klass kallad Polygon. Exemplet är extraherat från denna live demo (källkod).

- -
class Square extends Polygon {
-  constructor(length) {
-    // Här anropas föräldraklassens constructor med längd
-    // angiven för Polygons bredd och höjd
-    super(length, length);
-    // Notera: i underliggande klasser, måste super() anropas innan du
-    // kan använda 'this'. Utelämnande av detta kommer orsaka ett "reference error".
-    this.name = 'Square';
-  }
-
-  get area() {
-    return this.height * this.width;
-  }
-
-  set area(value) {
-    this.height = this.width = Math.sqrt(value);
-    this.area = value;
-  }
-}
- -

Användning av extends med inbyggda objekt

- -

Detta exempel utökar det inbyggda objektet {{jsxref("Date")}}. Exemplet är extraherat från denna live demo (källkod).

- -
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();
-  }
-}
- -

Utökning av null

- -

Utökning från {{jsxref("null")}} fungerar som en normal klass, förutom att prototype objektet inte ärver från {{jsxref("Object.prototype")}}.

- -
class nullExtends extends null {
-  constructor() {}
-}
-
-Object.getPrototypeOf(nullExtends); // Function.prototype
-Object.getPrototypeOf(nullExtends.prototype) // null
- -

Specifikationer

- - - - - - - - - - - - - - - - - - - -
SpecifikationStatusKommentar
{{SpecName('ES6', '#sec-class-definitions', 'extends')}}{{Spec2('ES6')}}Initial definition.
{{SpecName('ESDraft', '#sec-class-definitions', 'extends')}}{{Spec2('ESDraft')}} 
- -

Browserkompabilitet

- -

{{CompatibilityTable}}

- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support{{CompatChrome(42.0)}}{{CompatGeckoDesktop(45)}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
Array subclassing{{CompatChrome(43.0)}}{{CompatNo}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
-
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
FeatureAndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari MobileChrome for Android
Bassupport{{CompatNo}}{{CompatGeckoMobile(45)}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatChrome(42.0)}}
Array subklassning{{CompatNo}}{{CompatNo}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatChrome(43.0)}}
-
- -

Se även

- - diff --git a/files/sv-se/web/javascript/reference/classes/index.html b/files/sv-se/web/javascript/reference/classes/index.html deleted file mode 100644 index d3ac6aca7f..0000000000 --- a/files/sv-se/web/javascript/reference/classes/index.html +++ /dev/null @@ -1,383 +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 syntactical sugar over JavaScript's existing prototype-based inheritance. The class syntax is not introducing a new object-oriented inheritance model to JavaScript. JavaScript classes provide a much simpler and clearer syntax to create objects and deal with inheritance.

- -

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 ("Polygon" here).

- -
class Polygon {
-  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")}}:

- -
var p = new Polygon(); // ReferenceError
-
-class Polygon {}
-
- -

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.

- -
// unnamed
-var Polygon = class {
-  constructor(height, width) {
-    this.height = height;
-    this.width = width;
-  }
-};
-
-// named
-var Polygon = class Polygon {
-  constructor(height, width) {
-    this.height = height;
-    this.width = width;
-  }
-};
-
- -

Note: Class expressions also suffer from the same hoisting issues mentioned for Class declarations.

- -

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 constructors.

- -

Strict mode

- -

The bodies of class declarations and class expressions are executed in strict mode.

- -

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 a parent class.

- -

Prototype methods

- -

See also method definitions.

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

Static methods

- -

The static keyword defines a static method for a class. Static methods are called without instantiating their class and are also not callable when the class is instantiated. 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.sqrt(dx*dx + dy*dy);
-  }
-}
-
-const p1 = new Point(5, 5);
-const p2 = new Point(10, 10);
-
-console.log(Point.distance(p1, p2));
- -

Boxing with prototype and static methods

- -

When a static or prototype method is called without an object valued "this" (or with "this" as boolean, string, number, undefined or null), then the "this" value will be undefined inside the called function. Autoboxing will not happen. The behaviour will be the same even if we write the code in non-strict mode.

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

If we write the above code using traditional function based classes, then autoboxing will happen based on the "this" value overwhich the function was called.

- -
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
-
- -

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 {
-  speak() {
-    console.log(this.name + ' barks.');
-  }
-}
-
-var d = new Dog('Mitzie');
-d.speak();
-
- -

If there is a constructor present in sub-class, 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.');
-  }
-}
-
-var d = new Dog('Mitzie');
-d.speak();
-
- -

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

- -
var Animal = {
-  speak() {
-    console.log(this.name + ' makes a noise.');
-  }
-};
-
-class Dog {
-  constructor(name) {
-    this.name = name;
-  }
-  speak() {
-    console.log(this.name + ' barks.');
-  }
-}
-
-Object.setPrototypeOf(Dog.prototype, Animal);
-
-var d = new Dog('Mitzie');
-d.speak();
-
- -

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; }
-}
-
-var a = new MyArray(1,2,3);
-var 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 functions on an object's parent.

- -
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.');
-  }
-}
-
- -

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:

- -
var calculatorMixin = Base => class extends Base {
-  calc() { }
-};
-
-var 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('ES6', '#sec-class-definitions', 'Class definitions')}}{{Spec2('ES6')}}Initial definition.
{{SpecName('ESDraft', '#sec-class-definitions', 'Class definitions')}}{{Spec2('ESDraft')}} 
- -

Browser compatibility

- -

{{CompatibilityTable}}

- -
- - - - - - - - - - - - - - - - - - - - - -
FeatureChromeFirefox (Gecko)EdgeInternet ExplorerOperaSafari
Basic support{{CompatChrome(42.0)}}[1]
- {{CompatChrome(49.0)}}
{{CompatGeckoDesktop(45)}}13{{CompatNo}}{{CompatNo}}{{CompatSafari(9.0)}}
-
- -
- - - - - - - - - - - - - - - - - - - - - -
FeatureAndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari MobileChrome for Android
Basic support{{CompatNo}}{{CompatGeckoMobile(45)}}{{CompatUnknown}}{{CompatUnknown}}9{{CompatChrome(42.0)}}[1]
- {{CompatChrome(49.0)}}
-
- -

[1] Requires strict mode. Non-strict mode support is behind the flag "Enable Experimental JavaScript", disabled by default.

- -

See also

- - diff --git a/files/sv-se/web/javascript/reference/classes/static/index.html b/files/sv-se/web/javascript/reference/classes/static/index.html deleted file mode 100644 index 515f4fbfec..0000000000 --- a/files/sv-se/web/javascript/reference/classes/static/index.html +++ /dev/null @@ -1,179 +0,0 @@ ---- -title: static -slug: Web/JavaScript/Reference/Classes/static -tags: - - Klasser - - Metoder - - Statiska funktioner -translation_of: Web/JavaScript/Reference/Classes/static ---- -
{{jsSidebar("Classes")}}
- -

Nyckelordet static definierar en statisk metod för en klass.

- -

Syntax

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

Beskrivning

- -

Anrop på statiska metoder är gjorda direkt på klassen och kan inte göras genom instanser av klassen. Statiska metoder är ofta använda för att göra verktygsfunktioner.

- -

Att anropa statiska metoder

- -

Från en annan statisk metod

- -

För att anropa en statisk metod från en annan statisk metod av samma klass, kan du använda "this".

- -
class StaticMethodCall {
-  static staticMethod() {
-    return 'En statisk metod har blivit anropad';
-  }
-  static anotherStaticMethod() {
-    return this.staticMethod() + ' från en annan statisk metod!';
-  }
-}
-StaticMethodCall.staticMethod();
-// 'En statisk metod har blivit anropad'
-
-StaticMethodCall.anotherStaticMethod();
-// 'En statisk metod har blivit anropad från en annan statisk metod!'
- -

Från en klasskonstruktor och andra metoder

- -

Statiska metoder är inte tillgängliga genom att använda "this" från icke statiska metoder. Du behöver anropa dem genom att antingen använda klassnamnet: ClassName.staticMethodName() eller genom att anropa metoden som en egendom av konstruktorn: this.constructor.staticMethodName().

- -
class StaticMethodCall {
-  constructor() {
-    console.log(StaticMethod.staticMethod());
-    // 'En statisk metod har blivit anropad.'
-
-    console.log(this.constructor.staticMethod());
-    // 'En statisk metod har blivit anropad.'
-  }
-
-  static staticMethod() {
-    return 'En statisk metod har blivit anropad.';
-  }
-}
- -

Exempel

- -

Det följande exemplet visar flera saker:

- -
    -
  1. Hur en statisk metod implementeras på en klass.
  2. -
  3. Att en klass med en statisk medlem kan vara sub-klassad.
  4. -
  5. Hur en statisk metod kan och inte kan bli anropad.
  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 (Påverkas inte av förälderns instans.)
-
-console.log(tp.triple());
-// 'tp.triple is not a function'.
-
- -

Specifikationer

- - - - - - - - - - - - - - - - - - - -
SpecifikationStatusKommentar
{{SpecName('ES2015', '#sec-class-definitions', 'Class definitions')}}{{Spec2('ES2015')}}Första definition.
{{SpecName('ESDraft', '#sec-class-definitions', 'Class definitions')}}{{Spec2('ESDraft')}} 
- -

Webbläsarkompatibilitet

- -

{{CompatibilityTable}}

- -
- - - - - - - - - - - - - - - - - - - -
FunktionChromeFirefox (Gecko)Internet ExplorerOperaSafari
Grundlig support{{CompatChrome(42.0)}}{{CompatGeckoDesktop(45)}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
-
- -
- - - - - - - - - - - - - - - - - - - - - -
FunktionAndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari MobileChrome for Android
Grundlig support{{CompatNo}}{{CompatGeckoMobile(45)}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatChrome(42.0)}}
-
- -

 

- -

Läs också

- - diff --git a/files/sv-se/web/javascript/reference/index.html b/files/sv-se/web/javascript/reference/index.html deleted file mode 100644 index 4205970b93..0000000000 --- a/files/sv-se/web/javascript/reference/index.html +++ /dev/null @@ -1,51 +0,0 @@ ---- -title: JavaScript reference -slug: Web/JavaScript/Reference -tags: - - JavaScript - - NeedsTranslation - - TopicStub - - 'l10n:priority' -translation_of: Web/JavaScript/Reference ---- -
{{JsSidebar}}
- -

This part of the JavaScript section on MDN serves as a repository of facts about the JavaScript language. Read more about this reference.

- -

Global Objects

- -

This chapter documents all the JavaScript standard built-in objects, along with their methods and properties.

- -
{{page('/en-US/docs/Web/JavaScript/Reference/Global_Objects', 'Standard_objects_by_category')}}
- -

Statements

- -

This chapter documents all the JavaScript statements and declarations.

- -
{{page('/en-US/docs/Web/JavaScript/Reference/Statements', 'Statements_and_declarations_by_category')}}
- -

Expressions and operators

- -

This chapter documents all the JavaScript expressions and operators.

- -
{{page('/en-US/docs/Web/JavaScript/Reference/Operators', 'Expressions_and_operators_by_category')}}
- -

Functions

- -

This chapter documents how to work with JavaScript functions to develop your applications.

- - - -

Additional reference pages

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