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 AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
classChrome Full support 49
Notes
Full support 49
Notes
Notes From Chrome 42 to 48 strict mode is required. Non-strict mode support can be enabled using the flag "Enable Experimental JavaScript".
Edge Full support YesFirefox Full support 45IE No support NoOpera Full support 36Safari Full support 10.1WebView Android Full support 49
Notes
Full support 49
Notes
Notes From Chrome 42 to 48 strict mode is required. Non-strict mode support can be enabled using the flag "Enable Experimental JavaScript".
Chrome Android Full support 49
Notes
Full support 49
Notes
Notes From Chrome 42 to 48 strict mode is required. Non-strict mode support can be enabled using the flag "Enable Experimental JavaScript".
Firefox Android Full support 45Opera Android ? Safari iOS Full support 10.1Samsung Internet Android Full support 4.0nodejs Full support 6.0.0

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
See implementation notes.
See implementation notes.

See also

Document Tags and Contributors

Contributors to this page: mdnwebdocs-bot, yalvacee_
Last updated by: mdnwebdocs-bot,