Commit 87c83b04 authored by jaubourg's avatar jaubourg

Callbacks.add now accepts array-like objects (like Arguments). Now uses the...

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.
parent 8cc217ea
...@@ -94,12 +94,11 @@ jQuery.Callbacks = function( options ) { ...@@ -94,12 +94,11 @@ jQuery.Callbacks = function( options ) {
var start = list.length; var start = list.length;
(function add( args ) { (function add( args ) {
jQuery.each( args, function( _, arg ) { jQuery.each( args, function( _, arg ) {
var type; if ( jQuery.isFunction( arg ) && ( !options.unique || !self.has( arg ) ) ) {
if ( ( type = jQuery.type(arg) ) === "array" ) { list.push( arg );
} else if ( arg && arg.length ) {
// Inspect recursively // Inspect recursively
add( arg ); add( arg );
} else if ( type === "function" && ( !options.unique || !self.has( arg ) ) ) {
list.push( arg );
} }
}); });
})( arguments ); })( arguments );
...@@ -121,7 +120,7 @@ jQuery.Callbacks = function( options ) { ...@@ -121,7 +120,7 @@ jQuery.Callbacks = function( options ) {
remove: function() { remove: function() {
if ( list ) { if ( list ) {
jQuery.each( arguments, function( _, arg ) { jQuery.each( arguments, function( _, arg ) {
var index = 0; var index;
while( ( index = jQuery.inArray( arg, list, index ) ) > -1 ) { while( ( index = jQuery.inArray( arg, list, index ) ) > -1 ) {
list.splice( index, 1 ); list.splice( index, 1 );
// Handle firing indexes // Handle firing indexes
...@@ -170,7 +169,8 @@ jQuery.Callbacks = function( options ) { ...@@ -170,7 +169,8 @@ jQuery.Callbacks = function( options ) {
}, },
// Call all callbacks with the given context and arguments // Call all callbacks with the given context and arguments
fireWith: function( context, args ) { fireWith: function( context, args ) {
args = [ context, jQuery.merge( [], args || [] ) ]; args = args || [];
args = [ context, args.slice ? args.slice() : args ];
if ( list && ( !fired || stack ) ) { if ( list && ( !fired || stack ) ) {
if ( firing ) { if ( firing ) {
stack.push( args ); stack.push( args );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment