Bug Tracker

Opened 16 years ago

Closed 16 years ago

Last modified 11 years ago

#317 closed bug (fixed)

Unreachable code in jQuery constructor function.

Reported by: [email protected] Owned by:
Priority: major Milestone: 1.1a
Component: core Version: 1.1a
Keywords: Cc:
Blocked by: Blocking:

Description (last modified by john)

If a new jQuery object is created with the usual syntax ($('div', document.body)), the constructor function doesn't get far before it realises that it needs to call the new keyword on itself, with this line:

	if ( window == this )
		return new jQuery(a,c);

However, as you can see, only the two formal parameters are passed into this second call -- that is, any extra arguments are discarded. This would not be a problem of course, except that later in the function there is a provision for an extra function that may be passed in:

	// See if an extra function was provided
	var fn = arguments[ arguments.length - 1 ];

	// If so, execute it in context
	if ( fn && typeof fn == "function" )

By the time this code is reached, the extra un-named argument will have been discarded, whether or not it was present in the original call.

This bug could be circumvented if the original statement explicitly instantiated a new object (new jQuery('div', document.body, someFunction)) -- but since $(etc) is the conventional syntax, this feature is effectively unreachable by a normal jQuery call.

Change History (2)

comment:1 Changed 16 years ago by john

Description: modified (diff)
Milestone: 1.1
Priority: minormajor
Version: 1.1

comment:2 Changed 16 years ago by joern

Resolution: fixed
Status: newclosed

Fixed in SVN, the unreachable code is now removed.

Note: See TracTickets for help on using tickets.