Reading through the jQuery documentation about the event object and its constructor $.Event() I see:
The
newoperator is optional [when calling the constructor].
That’s cool! How did the jQuery people pull such a trick?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
John Resig explains this pretty well: http://ejohn.org/apps/learn/#36 and http://ejohn.org/apps/learn/#38
Basically,
Eventis a function and an object (functions are objects). The first line of Event checks if it is being called as a function or as an instance of the Event object (with the new operator).If you are looking for specifically how jQuery does it, look at line 3134-3138 of the jQuery source:
And explanation for this is on the jQuery forms.
Basically, on lines 3178-3194 the preventDefault event is added to the Event prototype. If the event is instantiated with
newit will be given this preventDefault method. Otherwise, it won’t be defined.