[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Classes/constructor [Back]  [Original]

- JavaScript | MDN

MDN Web Docs

View in English Always switch to English

Baseline Widely available

This feature is well established and works across many devices and browser versions. Its been available across browsers since 20163.

constructor class

In this article

constructor([arguments]) { ... }

class constructor class constructor SyntaxError

constructor

classes sample

js
class Square extends Polygon {
  constructor(length) {
    //  class 
    super(length, length);
    //  derived class super()  this 
    this.name = "Square";
  }

  get area() {
    return this.height * this.width;
  }

  set area(value) {
    this.area = value;
  }
}

base classes

js
constructor() {}

derived class

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

Specification
ECMAScript 2027 LanguageSpecification
# sec-static-semantics-constructormethod


Web Proxy Viewer  |  New URL  |  Original Page