class Square {
constructor (public width :number, public height :number, public color :string){
}
draw(){
let a = Math.random();
let square = `<div style="position:relative;
top:${a * 400}px;
left:${a * 400}px;
width:${this.width}px;
height : ${this.height}px;
background:${this.color}"></div>`;
document.body.insertAdjacentHTML( 'beforeend', square );
}
}
위 코드에서 constructor의 매개변수에 public을 직접해주면 아래 과정을 생략해줄 수 있는건가요..?
class Square {
private width: number;
private height: number;
private color: string;
constructor(width: number, height: number, color: string) {
this.width = width;
this.height = height;
this.color = color;
}
}