好像也只能这样...有木有大佬有更优的代码....![](static/image/smiley/ARU/aru-1x-2_173.png)
function myFunction(a,b,c,d,e) {
var a1;
var b1;
var c1;
var d1;
var e1;
if (a != undefined){
a1 = {
"sum": a
};
console.log(a);
}
if (b != undefined){
b1 = {
"sum": b
}
console.log(b);
}
if (c != undefined){
c1 = {
"sum": c
}
console.log(c);
}
if (d != undefined){
d1 = {
"sum": d
}
console.log(d);
}
if (e != undefined){
e1 = {
"sum": e
}
console.log(e);
}
return [a1, b1, c1, d1, e1];
}
function doIt(dododo) {
if (dododo === 0) {
set_str = "我在a1";
return myFunction(set_str, undefined, undefined, undefined, undefined)[0];
}
if (dododo === 4) {
set_str = "我在e1";
return myFunction(undefined, undefined, undefined, undefined, set_str)[4];
}
}
// 传一次参
doIt(0);// 打印: 我在a1
// 传一次参
doIt(4);// 打印: 我在e1
// 传两次参
doIt(0);// 打印: 我在a1
doIt(4);// 打印: 我在e1
|