实例代码“Ctrl+/”提示“F11/ESC”全屏 返回 格式化 恢复 运行
x
 
1
<!DOCTYPE html>
2
<html>
3
<head>
4
    <title>Function Type apply() Method Example</title>
5
    <script type="text/javascript">
6
        
7
        function sum(num1, num2){
8
            return num1 + num2;
9
        }
10
        
11
        function callSum1(num1, num2){
12
            return sum.apply(this, arguments);
13
        }
14
        
15
        function callSum2(num1, num2){
16
            return sum.apply(this, [num1, num2]);
17
        }
18
        
19
        alert(callSum1(10,10));   //20
20
        alert(callSum2(10,10));   //20
21
22
    </script>
23
</head>
24
<body>
25
26
</body>
27
</html>