diff options
author | jaubourg <j@ubourg.net> | 2012-04-25 18:18:44 +0200 |
---|---|---|
committer | jaubourg <j@ubourg.net> | 2012-04-25 18:25:51 +0200 |
commit | 87c83b04589e91a96adcfce788c6207295f83a5b (patch) | |
tree | 755ce2dc59c0ffe4b411d41c5ca76104cee02b06 | |
parent | 8cc217eac3c49515b8aff591a9a5a7e304f6e597 (diff) | |
download | jquery-87c83b04589e91a96adcfce788c6207295f83a5b.tar.gz jquery-87c83b04589e91a96adcfce788c6207295f83a5b.zip |
Callbacks.add now accepts array-like objects (like Arguments). Now uses the slice method of the args array in fireWith rather than a quite slow jQuery.merge.
-rw-r--r-- | src/callbacks.js | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/callbacks.js b/src/callbacks.js index 42f9315e9..b3b1c8a69 100644 --- a/src/callbacks.js +++ b/src/callbacks.js @@ -94,12 +94,11 @@ jQuery.Callbacks = function( options ) { var start = list.length; (function add( args ) { jQuery.each( args, function( _, arg ) { - var type; - if ( ( type = jQuery.type(arg) ) === "array" ) { + if ( jQuery.isFunction( arg ) && ( !options.unique || !self.has( arg ) ) ) { + list.push( arg ); + } else if ( arg && arg.length ) { // Inspect recursively add( arg ); - } else if ( type === "function" && ( !options.unique || !self.has( arg ) ) ) { - list.push( arg ); } }); })( arguments ); @@ -121,7 +120,7 @@ jQuery.Callbacks = function( options ) { remove: function() { if ( list ) { jQuery.each( arguments, function( _, arg ) { - var index = 0; + var index; while( ( index = jQuery.inArray( arg, list, index ) ) > -1 ) { list.splice( index, 1 ); // Handle firing indexes @@ -170,7 +169,8 @@ jQuery.Callbacks = function( options ) { }, // Call all callbacks with the given context and arguments fireWith: function( context, args ) { - args = [ context, jQuery.merge( [], args || [] ) ]; + args = args || []; + args = [ context, args.slice ? args.slice() : args ]; if ( list && ( !fired || stack ) ) { if ( firing ) { stack.push( args ); |