Ticket #317 (closed bug: fixed)
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
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.
