user2080105
user2080105

Reputation: 1702

How the browser knows that this is a jQuery event object and not a normal event

jQuery event object has some attributes and methods written in the jQuery library, I wonder how does the browser know that we are using a jQuery event object and not a normal event, because I notice we don't make any extra work that shows that!

Upvotes: 0

Views: 78

Answers (2)

the system
the system

Reputation: 9336

Your event handler never gets bound to the element. Instead it sits in the entry to window.jQuery.cache that is associated with the element.

What does get bound is a generic event handler. When an event occurs, that handler grabs the browser's event object, sees what type of event it was, looks up your handler in jQuery.cache, and invokes it.

But before invoking it, it makes a new event object to pass to your handler instead of the original (though it includes the original).

Upvotes: 2

gdoron
gdoron

Reputation: 150253

The browser doesn't know... jQuery captures the event, gets the normal event object and normalize it.

jQuery’s event system normalizes the event object according to W3C standards. The event object is guaranteed to be passed to the event handler. Most properties from the original event are copied over and normalized to the new event object.

Docs

Upvotes: 1

Related Questions