728x90 자바스크립트 클래스2 [javascript] 클래스 Class 선언 생성자 함수 getter setter constructor method Javascript 자바스크립트 클래스 1. 클래스(class) 선언 2. 생성자(constructor) 3. 함수(method) 4. getter 5. setter 자바스크립트에서 객체를 사용하기 위한 방법으로 Class가 있는데 다른 언어를 사용하던 사람에게는 아주 익숙한 키워드일 것이다. 클래스의 선언 class 원하는클래스명 { constructor(파라미터1, 파라미터2){ this.속성명1 = 파라미터1; this.속성명2 = 파라미터2; } } 위 예제 코드에서 constructor는 생성자를 의미한다. 생성자는 객체를 생성할때 자동으로 호출되는데, 전달되는 값을 통하여 객체를 생성함과 동시에 속성값을 초기화할수 있다. 물론 생략 가능하고, 내부에 객체생성시 원하는 기능을 입력하면 해당 기능.. 2021. 3. 29. [Javascript] Class 클래스 [get,set 구문 오류 필독] 자바스크립트에서의 클래스의 선언 및 활용 샘플 예제 ↓ class Person { //Class 내 생성자 constructor(name,age){ //this를 통한 내부 프로퍼티 초기화 this.name = name; this.age = age; } //static 변수 static blog = 'good-memory'; //static 함수 static speak = function (){ console.log('hello~'); } //getter get name (){ return this._name; } //setter set name (value){ this._name = value; } //Class 내 메소드 information(){ console.log(`my name is ${thi.. 2021. 2. 4. 이전 1 다음 728x90