Permalink
Browse files

Event: Make event dispatch optimizable by JavaScript engines

Closes gh-2834

- Do not assign to function parameters
- Do not pass arguments object to other functions
  • Loading branch information...
1 parent df2051c commit 9f268caaf43629addb9a1a2001ab341839300b14 @topaxi topaxi committed with dmethvin Jan 14, 2016
Showing with 9 additions and 5 deletions.
  1. +9 −5 src/event.js
View
@@ -283,19 +283,23 @@ jQuery.event = {
}
},
- dispatch: function( event ) {
+ dispatch: function( nativeEvent ) {
// Make a writable jQuery.Event from the native event object
- event = jQuery.event.fix( event );
+ var event = jQuery.event.fix( nativeEvent );
- var i, j, ret, matched, handleObj,
- handlerQueue = [],
- args = slice.call( arguments ),
+ var i, j, ret, matched, handleObj, handlerQueue,
+ args = new Array( arguments.length ),
handlers = ( dataPriv.get( this, "events" ) || {} )[ event.type ] || [],
special = jQuery.event.special[ event.type ] || {};
// Use the fix-ed jQuery.Event rather than the (read-only) native event
args[ 0 ] = event;
+
+ for ( i = 1; i < arguments.length; i++ ) {
+ args[ i ] = arguments[ i ];
+ }
+
event.delegateTarget = this;
// Call the preDispatch hook for the mapped type, and let it bail if desired

0 comments on commit 9f268ca

Please sign in to comment.