내용으로 건너뛰기
GaramX
사용자 도구
로그인
사이트 도구
검색
도구
문서 보기
이전 판
역링크
최근 바뀜
미디어 관리자
사이트맵
로그인
>
최근 바뀜
미디어 관리자
사이트맵
현재 위치:
home
»
javascript
»
callbackandthis
추적:
•
yaml
javascript:callbackandthis
이 문서는 읽기 전용입니다. 원본을 볼 수는 있지만 바꿀 수는 없습니다. 문제가 있다고 생각하면 관리자에게 문의하세요.
====== callback function에서의 this사용 ====== <code javascript> var A = /** @class */ (function () { function A() { this.i = 100; } A.prototype.a = function () { console.log('함수 a호출됨'); console.log('i:', this.i); // 1. 새로운 변수에 this //var that = this; //testCallback('1.', function() { // console.log('this.i:', that.i); // }); // 2. bind함수이용 //testCallback('2', function(){ // console.log('this.i', this.i);}.bind(this) ); // 2.1 bind함수이용 testCallback('2.1', this.myFun.bind(this)); }; A.prototype.add = function(k) { this.i = this.i + k; } A.prototype.myFun = function(){ console.log('this.i:', this.i); } return A; }()); function testCallback(name, test){ console.log('testCallback', name + '번째'); test(); } var myA = new A(); myA.add(200); myA.a(); </code>
javascript/callbackandthis.txt
· 마지막으로 수정됨: 2025/04/15 10:05 저자
127.0.0.1
문서 도구
문서 보기
이전 판
역링크
맨 위로