jQuery: The Write Less, Do More JavaScript Library

Ticket #2827 (closed bug: wontfix)

Opened 5 days ago

Last modified 4 days ago

$.each Treats Functions as Arrays

Reported by: dschoon Assigned to: anonymous
Type: bug Priority: minor
Milestone: 1.2.4 Component: core
Version: 1.2.3 Keywords:
Cc: Needs: Review

Description

Calling $.each on a function will result in it iterating over [0..arity], not the properties of the function object.

This is because $.each checks whether obj.length is defined, rather than checking whether the object is an array. In the case of a function object, Function.length will be defined, and it will be the arity of the function. This also screws user-defined types which have a length property.

Boo!

Attachments

dollar-each.diff (1.3 kB) - added by dschoon 5 days ago.

Change History

Changed 5 days ago by dschoon

Changed 5 days ago by dschoon

Patch attached. I guess I should have checked whether I have check-in privileges by default, but I assume not.

Changed 5 days ago by flesler

  • status changed from new to closed
  • resolution set to wontfix

I can tell you in advance, what a core developer will say: this function is internal, is the most used function all over the framework, so if this behavior (iterating functions) is not required by the core, then it won't be changed.

Also, this patch doesn't support any array-like (arguments, nodelist, jQuery object, etc).

I guess I should have checked whether I have check-in privileges by default, but I assume not.

There's no permissions system integrated into the SVN. But only those allowed can "legally" commit.

Changed 4 days ago by dschoon

Internal? Really? http://docs.jquery.com/Core/each#callback

I mean, if it's in the docs, it seems pretty public to me.

Changed 4 days ago by dschoon

Also, legit criticism for array-like objects; I guess the only technically correct solution would be to special-case for Functions.

Note: See TracTickets for help on using tickets.