1. bind method. The last fn parameter is redundant.
Copy codeThe Code is as follows: // Handle object literals
If (typeof type = "object "){
For (var key in type ){
This [name] (key, data, type [key], fn );
}
Return this;
}
2. CommentCopy codeThe Code is as follows: // Add which for click: 1 = left; 2 = middle; 3 = right
ChangeCopy codeThe Code is as follows: // Add which for mousedown/mouseup: 1 === left; 2 === middle; 3 === right
3. The data method defines the local variable internalKey, but the subsequent code still follows jQuery. expando.Copy codeThe Code is as follows: var internalKey = jQuery. expando, getByName = typeof name = "string", thisCache,
4. jQuery. event. add method, change arguments to e, and change apply to call to be better. Because only one parameter is passed: the event object.Copy codeThe Code is as follows: 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 "do not repeat the browser" principle, jQuery. event. add the following code:Copy codeThe Code is as follows: if (elem. addEventListener ){
Elem. addEventListener (type, eventHandle, false );
} Else if (elem. attachEvent ){
Elem. attachEvent ("on" + type, eventHandle );
}
Replace the followingCopy codeThe Code is as follows: 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 I don't know why jQuery. addEvent does not exist.