js条件语句之职责链数组

本文提供了一个简单的HTML页面结构示例,并展示了如何在页面中嵌入JavaScript代码以执行基本的控制台输出操作。通过定义一系列规则匹配和执行函数,探讨了网页与脚本之间的交互方式。
 1 <!DOCTYPE html>
 2 <html lang="en">
 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 </body>
14 <script>
15     const rules = [{
16         match: function(a, b, c) {
17             console.log(555);
18         },
19         action: function(a, b, c) {
20             console.log(555);
21         }
22     }, {
23         match: function(a, b, c) {
24             console.log(666);
25         },
26         action: function(a, b, c) {
27             console.log(666);
28         }
29     }, {
30         match: function(a, b, c) {
31             console.log(777);
32         },
33         action: function(a, b, c) {
34             console.log(777);
35         }
36     }]
37 
38     function demo(a, b, c) {
39         for (let i = 0; i < rules.length; i++) {
40             if (rules[i].match(a, b, c)) {
41                 return rules[i].action(a, b, c)
42             }
43         }
44     }
45 
46     demo(a, b, d);
47 </script>
48 
49 </html>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值