This translation is incomplete. Please help translate this article from English.

Sınıf ifadesi, prototip tabanlı belirli bir isme sahip yeni sınıflar oluşturur.

You can also define a class using a class expression. But unlike the class expression, the class declaration doesn't allow an existing class to be declared again and will throw a type error if attempted. 

Syntax

class adi [extends] {
  // class içerik
}

Açıklama

Bir sınıfın içeriği "strict" modda yürütülür. Constructor özelliği isteğe bağlıdır.

Class declarations are not hoisted (unlike function declarations).

Örnekler

Basit sınıf tanımlamaları

Bu örnekte ilk olarak Polygon adında bir sınıf oluşturduk. Hemen aşağısında bulunan Square sınıfını 'extends' kullanarak genişlettik. Note that super(), used in the constructor, can only be used in constructors and must be called before the this keyword can be used.

class Polygon {
  constructor(height, width) {
    this.name = 'Polygon';
    this.height = height;
    this.width = width;
  }
}

class Square extends Polygon {
  constructor(length) {
    super(length, length);
    this.name = 'Square';
  }
}

Attempting to declare a class twice

Tanımlanmış bir sınıfı yeniden tanımlarsanız aşağıdaki hata ile karşılaşırsınız.

class Foo {};
class Foo {}; // Uncaught TypeError: Identifier 'Foo' has already been declared

The same error is thrown when a class has been defined before using the class expression.

var Foo = class {};
class Foo {}; // Uncaught TypeError: Identifier 'Foo' has already been declared

Specifications

Specification Status Comment
ECMAScript 2015 (6th Edition, ECMA-262)
The definition of 'Class definitions' in that specification.
Standard Initial definition.
ECMAScript 2016 (ECMA-262)
The definition of 'Class definitions' in that specification.
Standard  
ECMAScript 2017 (ECMA-262)
The definition of 'Class definitions' in that specification.
Standard  
ECMAScript Latest Draft (ECMA-262)
The definition of 'Class definitions' in that specification.
Draft  

Browser compatibility

Update compatibility data on GitHub
DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung InternetNode.js
Basic supportChrome Full support 42Edge Full support YesFirefox Full support 45IE No support NoOpera ? Safari Full support 10.1WebView Android Full support 42Chrome Android Full support 42Edge Mobile Full support YesFirefox Android Full support 45Opera Android ? Safari iOS Full support 10.1Samsung Internet Android Full support 4.0nodejs Full support 6.0.0
Array subclassingChrome Full support 43Edge ? Firefox ? IE No support NoOpera ? Safari ? WebView Android Full support 43Chrome Android Full support 43Edge Mobile ? Firefox Android ? Opera Android ? Safari iOS ? Samsung Internet Android Full support 4.0nodejs ?
Allowed in sloppy modeChrome Full support 49Edge ? Firefox ? IE No support NoOpera ? Safari ? WebView Android Full support 49Chrome Android Full support 49Edge Mobile ? Firefox Android ? Opera Android ? Safari iOS ? Samsung Internet Android Full support 5.0nodejs ?

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown

See also

Document Tags and Contributors

Contributors to this page: yalvacee_
Last updated by: yalvacee_,