Bug Tracker

Modify

Ticket #317 (closed bug: fixed)

Opened 7 years ago

Last modified 14 months ago

Unreachable code in jQuery constructor function.

Reported by: henra..h+jQuery@… Owned by:
Priority: major Milestone: 1.1a
Component: core Version: 1.1a
Keywords: Cc:
Blocking: Blocked by:

Description (last modified by john) (diff)

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" )
		this.each(fn);

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

comment:1 Changed 7 years ago by john

  • Priority changed from minor to major
  • Version set to 1.1
  • Description modified (diff)
  • Milestone set to 1.1

comment:2 Changed 6 years ago by joern

  • Status changed from new to closed
  • Resolution set to fixed

Fixed in SVN, the unreachable code is now removed.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.