【发布时间】:2011-01-20 02:37:23
【问题描述】:
我有 2 个 jQuery 函数。一个叫另一个(理论上......)。它们是:
$.testFunction = function(arg1){
alert("testFunction(arg1)");
$.testFunction(arg1, "");
}
$.testFunction = function(arg1, arg2){
alert("testFunction(arg1, arg2)");
alert("arg1: " + arg1 + "\narg2: " + arg2);
}
我有两个函数,因为当我没有传递第二个参数时,我想调用它们的简单版本。 但是当我这样打电话时:
$.testFunction("first param");
alert("Before second call");
$.testFunction("first param", "second param");
它总是调用第二个,并且(在警报窗口中)输入:“testFunction(arg1, arg2)”然后是“arg1: first param arg2: undefined”。为什么会这样工作?当我只传递一个参数时,为什么不调用第一个函数?
【问题讨论】: