javascript 中的arguments模拟函数重载

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <script type="text/javascript">
        function sumGuo()
        {
            var result = 0;
            for(var i in arguments)
            {
                result += i;
            }
            return result;
            /*for(var i=0;i<arguments.length;i++)
            {
                result += arguments[i];
            }*/
        }
        alert(sumGuo(1,2,3,4,5));           //输出结果12345
        alert(sumGuo(1,2,3,4,5,6,7,8,9));   //输出结果123456789
    </script>
</head>
<body>
</body>
</html>

 

posted @ 2017-11-02 13:54  我将枕中记忆抹去任岁月浮光掠影  阅读(152)  评论(0编辑  收藏  举报