Why does jQuery.Event use preventDefault as an instance test?
On a discussion elsewhere (
http://tinyurl.com/3tcm6l5), I ran across the fact that jQuery.Event starts like this:
- jQuery.Event = function( src ) {
- // Allow instantiation without the 'new' keyword
- if ( !this.preventDefault ) {
- return new jQuery.Event( src );
- }
I'm curious as to why it's done this way rather than the more obvious
- jQuery.Event = function( src ) {
- // Allow instantiation without the 'new' keyword
- if (!(this instanceof jQuery.Event) ) {
- return new jQuery.Event( src );
- }
Although the current code works, if someone somehow did this:
- jQuery.preventDefault = true;
it would wreak havoc This would stop events from processing, except those constructed with "new" and would overwrite the jQuery.type function, and perhaps steal your girlfriend.
Is there some reason that the more obvious code won't work?
-- Scott