title: Javascript pattern: Conditional event handler
body: <p>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 something different depending on the instance's state.</p>
  
  <p><em>Pseudo code:</em></p>
  
  <pre><code>IF instance state IS 'active' AND link is clicked THEN call function A
  IF instance state IS 'inactive' AND link is clicked THEN call function B
  …
  </code></pre>
  
  <p>I'm wondering what's considered good practice to handle this case properly:</p>
  
  <ul>
  <li>Which patterns are commonly in use to achieve this?</li>
  <li>Are you using a conditional in the event handler?</li>
  <li>Or are binding and unbinding handlers when the state changes?</li>
  <li>Am I missing some obvious other/better solution?</li>
  </ul>
  
  <hr>
  
  <p><strong>UPDATE</strong></p>
  
  <p>While reading the answers so far, there seems to be a strong tendency towards the usage of a conditional within the handler. While I had secretly hoped that I might have missed an alternative, I've sort of expected this.</p>
  
  <p>I like @J-P's approach since it keeps the pairing of method and state separately, which seems more scaleable and maintainable than a simple <code>switch</code> or <code>if/else</code> statement.
  However, I'd be very interested to hear if this is solved differently elsewhere, maybe using an example from a different language? </p>