1. The bind method, the last parameter fn is redundant
// Handle object literals
if ( typeof type === "object" ) {
for ( var key in type ) {
this[ name ](key, data, type[key], fn) ;
}
return this;
}
2, comment
// Add which for click: 1 === left; 2 === middle; 3 === right
should be modified Copy the code for
// Add which for mousedown/mouseup : 1 = == left; 2 === middle; 3 === right
3, data method, defines the local variable internalKey, but subsequent code still uses jQuery.expando.
var internalKey = jQuery.expando, getByName = typeof name = == "string", thisCache,
4, jQuery.event.add method, arguments are changed to e, and apply is changed to call, which is better. Because only one parameter is passed: the event object.
elemData.handle = eventHandle = function( e ) {
// Discard the second event of a jQuery.event.trigger() and
// when an event is called after a page has unloaded
return typeof jQuery !== "undefined" && (!e | | jQuery.event.triggered !== e.type) ?
jQuery.event.handle.apply( eventHandle.elem, arguments ) :
undefined;
};
5, based on the principle of "do not detect browsers repeatedly", jQuery.event.add the following code
if ( elem.addEventListener ) {
elem.addEventListener( type, eventHandle, false );
} else if ( elem.attachEvent ) {
elem.attachEvent( "on" type, eventHandle );
}
should be replaced with the following:
jQuery.addEvent = document.addEventListener ?
function( elem, type, handle ) {
if ( elem.addEventListener ) {
elem.addEventListener( type, handle, false );
}
} :
function( elem, type, handle ) {
if ( elem.attactEvent ) {
elem.attactEvent( "on" type, handle );
}
};
In fact, jQuery already has jQuery.removeEvent, but for some reason there is no jQuery.addEvent.