Class
- Class 란?
객체를 생성하기 위한 템플릿 || 특별한 함수
constructor
- constructor 란?
생성자
class 로 생성된 객체를 생성하고 초기화하기 위한 특수한 메서드이다.
클래스 안에 단 한개만 존재할 수 있다.
- class 선언
class(키워드) test(클래스명) {
//메인로직
} //클래스 body
- 예시
//클래스 선언
class test {
costructor(test1,test2){
this.test = test1
this.test2 = test2
}
//메서드 형태의 동사
Tests(){
console.log(`아아 ${this.test1} ${this.test2} ${this.test1} ${this.test2} `)
}
}
//클래스의 매개변수의 값을 할당함 => 인스턴스 만들기
const micTest = new test('마이크','테스트')
micTest.Tests()// 출력 : 아아 마이크 테스트 마이크 테스트
'JavaScript' 카테고리의 다른 글
콜백 함수 이해하기 1일차 (0) | 2024.08.19 |
---|---|
DOM / Closure (클로저) (0) | 2024.08.18 |
메서드 setInterval/clearInterval/setTimeout (0) | 2024.08.16 |
실행 컨텍스트 /콜 스택(call stack)/ this / call메서드 /apply메서드 (0) | 2024.08.15 |
중첩객체/불변객체/얕은복사/깊은복사 (0) | 2024.08.14 |