Skip to content
Search

JavaScript:Class

lastmod 2022-12-08created 2022-12-083 edits

How to create a Class in JavaScript.

Literal-style class

var 인스턴스 = {
  프로퍼티1 : 초기값,
  프로퍼티2 : 초기값,

  메서드1 : function() {
    // ...
  },
  메서드2 : function() {
    // ...
  }
}

Function-style class

function 클래스이름() {
  this.프로퍼티1 = 초기값;
  this.프로퍼티2 = 초기값;

  this.메서드1 = function() {
    // ...
  }
  this.메서드2 = function() {
    // ...
  }
}

Prototype-style class

function 클래스이름() {
  this.프로퍼티1 = 초기값;
  this.프로퍼티2 = 초기값;
}

클래스이름.prototype.메서드1 = function() {
  // ...
}

클래스이름.prototype.메서드2 = function() {
  // ...
}

How to create an instance

var 인스턴스 = new 클래스이름(); 

See also

Favorite site

author Zer0 sitemap