How to remove a window's onclick event (Pebble.js)

139 views Asked by At

I am writing a Pebble app in Pebble.js which needs to run different functions when the same button is pressed at different times throughout the app.

I can easily associate a function with a button:

dispWindow.on('click', 'up', function(e) {
  doSomething();
});

After doSomething runs a few times, I need to change what happens when the user clicks the "up" button in the dispWindow Window. I can add this code:

dispWindow.on('click', 'up', function(e) {
  doSomethingElse();
});

However, when the user clicks the "up" button, doSomething and doSomethingElse both fire. How do I remove doSomething from the "up" button?

1

There are 1 answers

2
Ryan K On BEST ANSWER

You can use the off event, like this:

dispWindow.off('click');

Then, call the on event again after that:

dispWindow.on('click', 'up', function(e) {
  doSomethingElse();
});