zoukankan      html  css  js  c++  java
  • js条件语句之职责链数组

     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>
  • 相关阅读:
    php解析文本文件呈现在表格上
    nyoj 1058部分和问题
    nyoj 488素数环
    nyoj 82迷宫寻宝(一)
    nyoj58最少步数
    nyoj 325 zb的生日
    nyoj 20 吝啬的国度
    nyoj 349 Sorting It All Out
    nyoj 284
    PPT基础整理
  • 原文地址:https://www.cnblogs.com/cisum/p/7754974.html
Copyright © 2011-2022 走看看