2016-05-16 160 views
0

有沒有辦法跳過一個函數或構造函數中的參數。我相信有,但是每當我嘗試用構造函數來做時,我都會收到一條錯誤消息。如何在函數中傳遞參數?

的Javascript

function Black(race, nation){ 
     this.race = race ||"black"; 
     this.nation = nation || "unknown"; 


    } 

    black1 = new Black(,"America"); 
    black2 = new Black( ,"UK"); 
    black3 = new Black(,"S America"); 

    console.log(black1, black2, black3); 
+9

通'undefined'或'null'。 – Pointy

回答

1

使用var black1 = new Black(null, "America");