강의

멘토링

커뮤니티

Inflearn Community Q&A

barricade300268's profile image
barricade300268

asked

[React Part 1] Learning React by Building and Comparing

[PureJS 2] Tab 3 (Solution)

delegate에 관하여 질문있습니다.

Written on

·

332

1

bindEvents() {
        // delegate(this.element, "click", "li", (event) =>
        //     this.handleClick(event)
        // );
        on(this.element, "click", (event) => this.handleClick(event));
    }

    handleClick(event) {
        console.log(tag, event.target);
        const value = event.target.dataset.tab;
        this.emit("@change", { value });
  }

위 코드에서 delegate 부분을 helper.js의 on 메서드를 이용하여 구현해보았는데요

지금처럼 tab-view안에 li만 있을경우는 delegate를 쓸때와 동일한 것이 맞나요?

아니면 delegate를 사용하여야만 하는 이유가 있을까요?

읽어주셔서 감사합니다.

MVCreact

Answer 1

2

jeonghwan님의 프로필 이미지
jeonghwan
Instructor

this.element의 자식 엘리먼트에서 발생할 이벤트 처리기를 등록하기 위해서 delegate 함수를 사용했어요. on이 하나의 엘리먼트에 직접 이벤트 처리기를 등록하는 것과 차이가 있습니다.

제이쿼리에도 같은 일을 하는 함수가 있는데 참고해 주세요.

barricade300268's profile image
barricade300268

asked

Ask a question