我有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