2012-04-22 60 views
0

我必須通過一個匿名函數的返回值作爲一個參數傳遞給另一個功能hello1()傳遞返回值到另一個功能

hello1 = function(x,m) { console.log(m) }; 

return $(this).each(function() { 
     var self = this; 
     hello1(something , function(){ return(this); }); 
}); 

當我做的console.log(米)它顯示。 .. return(this);而不是對象

回答

2

m是一個函數,所以要得到它的結果你必須調用它。

hello1 = function(x,m) { console.log(m()) }; 
+0

只是想說我自己。 :P – DanRedux 2012-04-22 04:43:07

+0

謝謝ricochet1k – user1184100 2012-04-22 05:02:21

+0

沒問題。得到更快的@DanRedux! – ricochet1k 2012-04-22 05:04:33

0

爲什麼你不能傳遞「自我」?

hello1 = function(x,m) { console.log(m) }; 

return $(this).each(function() { 
     var self = this; 
     hello1(something , self }); 
}); 
相關問題