We're looking for a user researcher to understand the needs of developers and designers. Is this you or someone you know? Check out the post: https://mzl.la/2IGzdXS

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

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support42 Yes45 No ?10.1
Array subclassing43 ? ? No ? ?
Allowed in sloppy mode49 ? ? No ? ?
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support4242 Yes45 ?10.14.0
Array subclassing4343 ? ? ? ?4.0
Allowed in sloppy mode4949 ? ? ? ?5.0

See also

Document Tags and Contributors

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