JS - Class 프러퍼티

JD·2021년 9월 30일
0

class 프러퍼티 생성 예제 입니다

  
 class Rect{
	//생성자 에서 프러퍼티 추가
	constructor(h,w){
		this.h = h;
		this.w = w;
	}	
}

var obj = new Rect(10,5);
console.log(obj.h,obj.w);

 class Rect{
		//메소드 에서 프러퍼티 추가
		area(h,w){
			this.h = h;
			this.w = w;
			return this.h*this.w;
		}
 }

0개의 댓글