私はいくつかのコードを持っています..ala
$.fn.someObj= function(){
this.opt = {
whatever : 'somevalue',
whateve2 : 'more values'
}
this.someMethod = function(){
//do something
$(someElem).bind('click',function(){
this.someOTHERMethod(); <----- ISSUE HERE
})
}
this.someOTHERMethod = function(){
// do more stuff
}
this.init = function(data){
$.extend(this.opt, data);
this.someMethod();
};
};
クロージャを作成して問題を修正できます。
var that = this;
//code
that.someOTHERMethod(); <--- works
または、メソッドから「this」を削除した場合:
someOTHERMethod = function(){}
and just call it: someOTHERMethod(); < ---- works
しかし、クロージャーなしでその外側の機能を取得するためのよりエレガントな方法があるかどうか疑問に思っていますか?何か案は?