給定一個正常的功能,如何選擇變量分配給函數的參數? -Javascript
function descriptions(awesome, cool, alright){
return (awesome || "no one") + " is awesome. " + cool + " is cool. " +
+ alright + " is alright";
}
descriptions("jane", "jack", "jefferson");
//returns "jane is awesome. jack is cool. jefferson is alright."
我想用同樣的功能,但只喜歡傳像這樣的最後兩個參數:
descriptions(cool : "john", alright : "jane"); //I would like a statement similar to this that works.
//should return "no one is awesome. jack is cool. jefferson is alright."
如何將上面做什麼?
你不能。 JS不支持命名參數。 – zerkms
我應該刪除我的問題嗎? –
讓我們來看看社區的想法。這是一個有效的問題,「否」是一個完美的答案。 – zerkms