반응형
Recent Posts
Recent Comments
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

Real Vectorism. 훨씬 더 입체적으로...

자바스크립트에서의 Class 본문

JavaScript

자바스크립트에서의 Class

grast 2020. 6. 23. 16:27
반응형
class Test {
    constructor(idx, name, nick, regdate) {
        this.idx = idx;
        this.name = name;
        this.nick = nick;
        this.regdate = regdate;
    }
	
    setIdx(idx) { this.idx = idx; return this; }
    setName(name) { this.name = name; return this; }
    setNick(nick) { this.nick = nick; return this; }
    setRegdate(regdate) { this.regdate = regdate; return this; }

    getIdx() { return this.idx; }
    getName() { return this.name; }
    getNick() { return this.nick; }
    getRegdate() { return this.regdate; }
}

뭔가 헷갈린다.

 

01. 클래스 안에서 변수선언이 안된다. 생성자에서 this.변수명 으로 선언과 정의를 동시에 해주는게 최선인가보다.

02. 생성자와 함수만 정의한다. 이건 좀 적응하기 힘들다.

03. 객체 자신을 리턴하는 방식이 통한다. 체이닝도 되겠지만 뭔가 더 재밌는 문법을 찾은것 같다.

04. 앞으로 객체로 인스턴스화 하려면 예시코드 기준 new Test(idx, name, nick, regdate) 형식으로 써먹으면 된다

 

써먹기에 아주 좋은 기능이긴 한데 아무리 그래도 적응을 해야지...

반응형
Comments