3

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?

Ryan K
  • 3,985
  • 4
  • 39
  • 42
dybm
  • 126
  • 1
  • 2
  • 8

1 Answers1

1

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();
});
Ryan K
  • 3,985
  • 4
  • 39
  • 42
  • I tried your suggestion but it didn't work. By taking out the 'up' section I got it to work though: `dispWindow.off('click');` – dybm Aug 11 '15 at 17:51
  • Whoops. I fixed my answer. Check the check-mark if this answer worked for you, btw. – Ryan K Aug 11 '15 at 17:55