我有2个jQuery函数。一个叫另一个(理论上......)。它们是: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:第一个参数ARG2:未定义 ”。为什么这样工作?为什么当我只传递一个参数时不会调用第一个函数?
谢谢大家!我想,这是像在Java中,我可以写重载的方法! - – user196776 2010-02-23 15:18:34