본문 바로가기

코딩테스트 with JS

Class 만들기

  • 클래스를 정의하여 사용할 수 있다.
  • constuctor 함수는 클래스 생성과 함께 호출되는 함수이다.
class People {
    constructor(name){
        this.count = 0
        this.name = name
    }
}

let people = []

for(let i=0; i<3; i++){
	const p = new People(i)
	people.push(p)
}

// people = [ People, People, People ]

 

'코딩테스트 with JS' 카테고리의 다른 글

멀티 소팅(multi sorting)  (0) 2022.05.11
결정 알고리즘  (0) 2022.05.04
Deep Copy  (0) 2022.05.04
swap  (0) 2022.05.02
array 중복 제거 및 중복 값 찾기  (0) 2022.04.28