Skip to content

Instantly share code, notes, and snippets.

@tvandervossen
Created November 4, 2011 10:25
Show Gist options
  • Save tvandervossen/1339061 to your computer and use it in GitHub Desktop.
Save tvandervossen/1339061 to your computer and use it in GitHub Desktop.
Callback or custom event?
Hey, I’m playing around with a multitouch gesture recognition API
for Mobile Safari. Now I’m wondering; would you prefer to define the
event handler in a callback, like this:
recognize.tap(element, function() {
log('Tapped');
});
Or would you prefer the recognizer to fire a custom event, like this:
recognize.tap(element);
element.bind('tap', function() {
log('Tapped');
});
Which one do you like best? Why?
@egorFiNE
Copy link

egorFiNE commented Nov 4, 2011

Event. Consistency.

@flurin
Copy link

flurin commented Nov 4, 2011

I think firing an event is more "natural" as it fit's better with current models (tap is something that "happens" just like "click"). Also keeping track of event handlers is mostly done for you, with custom callbacks that's harder.

@pawelkomarnicki
Copy link

Event, feels right

@stravid
Copy link

stravid commented Nov 4, 2011

Version 2. This way I can setup all my tap-able elements in my setup code and then bind / unbind my event handlers whenever I want without having the "recognize" module around.

@flurin
Copy link

flurin commented Nov 4, 2011

@stravid, indeed: decoupling like this is easier to manage in the end.

@mislav
Copy link

mislav commented Nov 4, 2011

Check out touch.js and gesture.js of Zepto

@tvandervossen
Copy link
Author

@mislav I’m familiar with Zepto but for anything but trivial multitouch support you can’t get away from having to define gesture recognizers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment