私は、実際の関数はもう少し複雑ですが、ここで問題の簡単な例である。このこのコンテキストを自己呼び出し関数にバインドする方法は?
// 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);'? –
矢印機能? –