1
我有一個函數A,它在運行時接受另一個函數B作爲參數並調用它。問題是函數B需要一些參數,但我不知道如何傳遞給函數B,帶有參數,在功能A.在不調用函數的情況下爲自定義參數賦值函數
例子:
function callerFunction(c)
{
alert("The caller is calling the function!");
c(c.arguments);
};
var a = "hello";
function thisOne(d)
{
d = "I changed my way";
alert(d);
};
callerFunction(/* I NEED TO PASS THE 'thisOne' with the parameter/variable 'a' here, and then call it inside 'callerFunction' */);
我也想過這個,但有沒有另一種方式?我不喜歡另一個調用我需要的函數的函數;這種新的「中間」功能沒有辦法。 – sigur 2014-10-09 19:42:53
@sigur這是用閉包和一流功能的語言來完成這個最直接的方法。你會發現這是一個非常普遍的模式。 – cdhowie 2014-10-15 15:29:41