나는 실제 기능은 좀 더 복잡하다이이 컨텍스트를 자체 호출 함수에 바인드하는 방법은 무엇입니까?
// this is defined here and works just fine.
(function(){
this.doSomething()
// this is undefined here.
}/*tried .bind(this) here, but it didn't seem to help*)();
같은 자기 호출 함수 내에서 this
을 얻으려고 노력하지만, 여기에 문제의 간단한 예입니다입니다.
this
문맥을 함수 외부의 var self = this
외에도 위와 같은 자체 호출 함수에 전달하고 내부에서 주소를 self.doSomething()
으로 지정하려면 어떻게해야합니까?
'(function (self) { self.doSomething(); }) (this);'? –
화살표 기능? –