Javascript pattern: Conditional event handler

前端 未结 5 433
轮回少年
轮回少年 2021-01-27 03:29

Given e.g. a class instance of some sort has a state (e.g. \'active\', \'inactive\', …). The instance also attaches a click event to e.g. a link but the event handler does somet

5条回答
  •  忘掉有多难
    2021-01-27 04:14

    You use can some kind of dispatcher:

    $link.on('click', function () {
      (state ? A : B).call();
    });
    

提交回复
热议问题