Javascript pattern: Conditional event handler

前端 未结 5 399
轮回少年
轮回少年 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:02

    id say you just check the click event. Then in the click event check the instance state

    link.live('click', function() {
     switch(instance.state){
      case 'active': function A(); break;
      case 'inactive': function B(); break;
     }     
    }
    

提交回复
热议问题