【发布时间】:2011-01-14 05:24:14
【问题描述】:
我的 JavaScript 函数定义如下:
function printCompanyName(company1, company2, company3, company4, company5)
{
document.write("<p>" + company1 + "</p>");
document.write("<p>" + company2 + "</p>");
document.write("<p>" + company3 + "</p>");
document.write("<p>" + company4 + "</p>");
document.write("<p>" + company5 + "</p>");
}
并称之为:
printCompanyName("Dell, Microsoft, Apple, Gizmodo, Amazon");
但我得到以下输出:
Dell, Microsoft, Apple, Gizmodo, Amazon
undefined
undefined
undefined
undefined
什么给了!?我一直试图弄清楚这一点。我要:
Dell
Microsoft
Apple
Gizmodo
Amazon
【问题讨论】:
-
让这成为你的教训!在您(搜索,然后询问)stackoverflow 之前不要花费超过 1 小时。
标签: javascript function argument-passing optional-parameters