首页 > 其他 > 详细

函数的使用场景- 作为其他变量的值

时间:2019-12-08 20:42:13      阅读:78      评论:0      收藏:0      [点我收藏+]

函数作为其他变量的值。可以直接调用;

 

 1 <!DOCTYPE html>
 2 <html lang="zh">
 3 
 4 <head>
 5     <meta charset="UTF-8">
 6     <meta name="viewport" content="width=device-width, initial-scale=1.0">
 7     <meta http-equiv="X-UA-Compatible" content="ie=edge">
 8     <title>Document</title>
 9 </head>
10 
11 <body>
12 
13     <script>
14 
15 
16 
17         function foo(x, y) {
18             if (x > y) {
19                 return x;
20             } else {
21                 return y;
22             }
23         }
24 
25         // 将 foo 函数作为变量 bar 的值
26         var bar = foo;
27 
28         console.log(foo(12, 88))
29         console.log(bar(12, 66))
30 
31     </script>
32 </body>
33 
34 </html>

 

函数的使用场景- 作为其他变量的值

原文:https://www.cnblogs.com/wszzj/p/12006805.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!