]> source.dussan.org Git - jquery.git/commitdiff
Callbacks.add now accepts array-like objects (like Arguments). Now uses the slice...
authorjaubourg <j@ubourg.net>
Wed, 25 Apr 2012 16:18:44 +0000 (18:18 +0200)
committerjaubourg <j@ubourg.net>
Wed, 25 Apr 2012 16:25:51 +0000 (18:25 +0200)
src/callbacks.js

index 42f9315e95b15e7a99728eb408bc6e9e96ff70d0..b3b1c8a69ed07ef1da6014a1f6f37f12f1f73919 100644 (file)
@@ -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 );