Bug Tracker

Opened 14 years ago

Closed 14 years ago

#5209 closed bug (duplicate)

$().ready() assumes nothing is added to $.readyList during processing of $.readyList

Reported by: brianfreud Owned by:
Priority: major Milestone: 1.4
Component: core Version: 1.3.2
Keywords: patch Cc:
Blocked by: Blocking:

Description

If you have several $() functions, and want to control their load order, there's not currently any way to do it. $.ready() runs $.each() on $.readyList, and $.each assumes that the array is static. If, then, a function in $() tries to control its own position in $.readyList, or for whatever reason, you were to add a new $() closure within a $() function, neither would currently run.

Example: $(function ($) {

if (jQuery.readyList.length > 1) { Ensure that this loads *after* everything else also running at document ready.

jQuery.readyList.push(arguments.callee);

} else { alert('I'm running last.');

}(jQuery));

Currently, 'I'm running last.' will never alert. This $() function gets only a single chance to run, on the first time $.each() passes over it.

Fix: Change the following in $.ready (lines 3028 - 3037):

			// If there are functions bound, to execute
			if ( jQuery.readyList ) {
				// Execute all of them
				jQuery.each( jQuery.readyList, function(){
					this.call( document, jQuery );
				});

				// Reset the list of functions
				jQuery.readyList = null;
			}

to this:

			// If there are functions bound, to execute
			if ( jQuery.readyList ) {
				// Execute all of them
                                var readyList = jQuery.readyList;
				while( readyList.length) {
					readyList[0].call( document, jQuery );
					readyList.splice(0,1);
				};
			}

Change History (1)

comment:1 Changed 14 years ago by flesler

Resolution: duplicate
Status: newclosed

This is already fixed in trunk, I'm closing as duplicate.

Note: See TracTickets for help on using tickets.