Javascript pattern: Conditional event handler

前端 未结 5 420
轮回少年
轮回少年 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 03:52

    Which patterns are commonly in use to achieve this? Something like this
    Are you using a conditional in the event handler? Yes, see example
    Or are binding and unbinding handlers when the state changes? Nope, but it's a possibility.
    Am I missing some obvious other/better solution? I don't think so

提交回复
热议问题