I\'m new to JavaScript and a little bit confused with the duck typing concept. As far as I can tell, I understood the concept. But that leads to a strange consequence in my thou
As you are using a specific framework to capture your events, i think that you should assume that the originalEvent is always defined. If it isn't, then it is probably a good thing to throw an error as something clearly went wrong somewhere in the capture of the event.
However, the event could be a MouseEvent or a TouchEvent, also, the webkitForce property may not be supported. These are the kind of cases that you might want to detect :
// assume that originalEvent is always be defined by jQuery
var originalEvent = e.originalEvent.originalEvent;
if (originalEvent instanceof TouchEvent) { // if touch events are supported
// the 'touches' property should always be present in a TouchEvent
var touch = originalEvent.touches[0];
if (touch) {
if (touch.webkitForce) {
// ...
} else {
// webkitForce not supported
}
} // else no finger touching the screen for this event
} else {
// probably a MouseEvent
}