使用arguments实现多个参数的求和,(不确定多少个参数)

 1 <!DOCTYPE HTML>
 2 <html>
 3 <head>
 4 <meta charset="utf-8">
 5 <title>无标题文档</title>
 6 <script type="text/javascript">
 7 function sum(){
 8     var result = 0;
 9     for(var i=0; i<arguments.length; i++){
10         result += arguments[i];
11     }
12     return result;
13 }
14 alert(sum(12,6,86,86,86,86,86,8))
15 </script>
16 </head>
17 <body>
18 </div>
19 </body>
20 </html>

 

你可能感兴趣的:(arguments)