标签:
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> </head> <body> <script> //fn1(1, 2, 3, 5); function fn1() { alert(arguments) // object alert(arguments.length) // 4 alert(arguments[arguments.length - 1]) // 5 } // 课后小练习: alert(sumOrSub(1, 2, 3, ‘+‘)); // 6 alert(sumOrSub(10, 2, 3, 4, ‘-‘)); // 1 function sumOrSub() { var total = 0; var flag = arguments[arguments.length - 1]; switch (flag) { case ‘+‘ : for (var i = 0; i < arguments.length - 1; i++) {total += arguments[i];} break; case ‘-‘ : for (var i = 1; i < arguments.length - 1; i++) {total += arguments[i];} total = arguments[0] - total; break; case ‘*‘ : break; case ‘/‘ : break; } return total; } </script> </body> </html>
标签:
原文地址:http://www.cnblogs.com/bravolove/p/5983064.html