this바인딩1 자바스크립트 this binding 자바스크립트에서는 this.를 callback 등으로 전달할때 this의 class 정보가 무시됩니다. 예를 들어 아래와 같은 코드가 있습니다. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 class Test { constructor(a, b) { this.a = a this.b = b this.test = document.querySelector('.box') this.test.addEventListener('click', this.onClick) } onClick() { const tot = this.a + this.b console.log("a+b: " + tot) } } t = new Test(1,2) Colored by Color Scripter cs clickMe.. 2021. 5. 13. 이전 1 다음