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