0

これが私の問題です:

私は2つの変数を持っています:

var func = function() {
   $(dialog).dialog("close");
}

var m = "hello"

そして私はメソッドを呼び出します

this.xyz(func , m)

メソッドxyzは次のようになります

xyz : function(func, m) {
   //there is an OK button on which I am calling click event
   click: function() {
         func();
   }
}    

アプローチ-1func();を置き換えると、xyz内になります。$(dialog).dialog( "close");を使用します。完璧に動作します

アプローチ-2、ただしfunc(); ボタンをクリックしてもダイアログボックスは閉じません

アプローチ2を使いたいのですが、うまくいきません

thnx

4

2 に答える 2

0

新しいスコープが失われることを忘れているようです。新しい関数thisバインドまたは適用する必要があります。

xyz : function(func, m) {
   //there is an OK button on which I am calling click event
   click: function() {
         func.apply(this);
   }
}  
于 2012-08-24T01:28:46.577 に答える
0

変数を渡すだけで機能しました

xyz : function(func, m) {
 //there is an OK button on which I am calling click event
 click: func 
}
于 2012-08-24T02:10:20.193 に答える