]> source.dussan.org Git - jquery.git/commitdiff
Event: Make event dispatch optimizable by JavaScript engines
authorDamian Senn <jquery@topaxi.codes>
Thu, 14 Jan 2016 20:24:43 +0000 (21:24 +0100)
committerDave Methvin <dave.methvin@gmail.com>
Wed, 27 Apr 2016 13:13:16 +0000 (09:13 -0400)
Closes gh-2834

- Do not assign to function parameters
- Do not pass arguments object to other functions

src/event.js

index e382de6d2900a42f97a2a09580fb717adef3479f..4015f87688a7e6984c14902baad149d5728ed8ab 100644 (file)
@@ -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