Skip to main content

Bug Tracker

Side navigation

#14481 closed bug (wontfix)

Opened October 24, 2013 06:32AM UTC

Closed October 24, 2013 02:33PM UTC

Last modified October 24, 2013 02:40PM UTC

jQuery .trigger(event,args) barfs on {length:0} as handler argument

Reported by: Owned by:
Priority: low Milestone: None
Component: core Version: 2.0.3
Keywords: Cc:
Blocked by: Blocking:


jQuery 1.8.3 until at least jQuery 2.0.3 mess up the handling of event-handler parameters supplied via .trigger, when the parameter is an object with a "length" property.

In line 4556 (jquery-2.0.3.js, function "trigger", line jQuery.makeArray( data, [ event ])) jQuery makes an array out of the parameter object (why in f**ks name?)... and according to a painful single-step trace, the length property is extended onto the "new" data local variable... which causes the argument to vanish entirely and the handler not recieving it (setting a.length=0 will wipe the array clean!).

A test case is available at (see the JS console!). This behavior is neither mentioned on the docs of .trigger() nor on the docs of .on().


Attachments (0)
Change History (4)

Changed October 24, 2013 02:13PM UTC by timmywil comment:1

component: unfiledcore
keywords: → needsreview
priority: undecidedlow
status: newopen

makeArray supports extending array-like objects (such as jQuery instances). However, we could ensure the object is not a plain object. I know we've gone round and round on this, but what are the team's thoughts?

Changed October 24, 2013 02:21PM UTC by dmethvin comment:2

I'm not sure whether any code does .trigger("click", arguments) but if it did any "fix" would break that. So I'm inclined to leave it as-is and document it.

There's an easy workaround, always put the object in an Array, like [ {length: 0} ]. You have to pass an array if you pass multiple args, but it was made optional for the single-arg case and that has been a pain in the butt ever since because of things like this.

Changed October 24, 2013 02:33PM UTC by timmywil comment:3

keywords: needsreview
resolution: → wontfix
status: openclosed

yea, agreed. Forgot about the arguments case.

Changed October 24, 2013 02:40PM UTC by timmywil comment:4