Bug Tracker

Modify

Ticket #8104 (closed bug: wontfix)

Opened 2 years ago

Last modified 23 months ago

Problem with objects that have a .length property

Reported by: eamonn.kearns@… Owned by: eamonn.kearns@…
Priority: high Milestone: 1.next
Component: core Version: 1.5
Keywords: Cc:
Blocking: Blocked by:

Description

If you create a class with a .length property and try to bind events to it, jQuery throws an Exception.

 http://www.jsfiddle.net/Cg8tf/

The problem exists as a result of the makeArray function, which assumes that if the object has a length property, it is an array.

Change History

comment:1 Changed 2 years ago by rwaldron

  • Priority changed from undecided to low
  • Resolution set to worksforme
  • Status changed from new to closed
  • Component changed from unfiled to core

Tested in IE6-7-8, Firefox 3.6.12 - 4b10, Opera 9.x 10.x, Chrome latest and Safari 5

Did I miss the one you're getting errors in?

 http://www.jsfiddle.net/rwaldron/Cg8tf/4/

comment:2 Changed 2 years ago by eamonn.kearns@…

Yes, you missed it. Uncomment the declaration of the "this.length = 0" and it stops working, as per the comment directly above the commented out "this.length = 0".

I can even post the lines of code that cause this problem to exist at all, if you like.

comment:3 Changed 2 years ago by jitter

  • Priority changed from low to high
  • Status changed from closed to reopened
  • Resolution worksforme deleted
  • Milestone changed from 1.next to 1.5.1

Less convoluted  test case

As noted by the reporter, the problem lies in the .makeArray function.

comment:4 Changed 2 years ago by jitter

  • Status changed from reopened to open

comment:5 follow-up: ↓ 6 Changed 2 years ago by eamonn.kearns@…

I fiddled around with potential solutions. typeof gives "object" on arrays, so that won't work, but using the .constructor property seems to.

 http://jsfiddle.net/dqqCv/1/

Now, I haven't tested this in either Safari or IE, but it works in both Firefox and Chrome (which leads me to suspect it will work in Safari considering they both use Webkit, so it should also work in Konqueror).

comment:6 in reply to: ↑ 5 ; follow-ups: ↓ 7 ↓ 8 Changed 2 years ago by rwaldron

  • Owner set to eamonn.kearns@…
  • Status changed from open to pending

Why not use jQuery.type()?

Replying to eamonn.kearns@…:

I fiddled around with potential solutions. typeof gives "object" on arrays, so that won't work, but using the .constructor property seems to.

 http://jsfiddle.net/dqqCv/1/

Now, I haven't tested this in either Safari or IE, but it works in both Firefox and Chrome (which leads me to suspect it will work in Safari considering they both use Webkit, so it should also work in Konqueror).

Also...

alert-less:

 http://www.jsfiddle.net/rwaldron/UJzgM/4/

comment:7 in reply to: ↑ 6 Changed 2 years ago by jitter

Replying to rwaldron:

Also...

alert-less:

 http://www.jsfiddle.net/rwaldron/UJzgM/4/

:-/ ummm.. ok, sorry to have bothered you with my nasty alerts from 1999

comment:8 in reply to: ↑ 6 Changed 2 years ago by anonymous

Replying to rwaldron:

Why not use jQuery.type()?

Because I am not 100% familiar with the API and was offering any potential solution, knowing that if there was a jQuery specific one that you guys would know how to do it.

comment:9 Changed 2 years ago by jitter

  • Status changed from pending to open

comment:10 follow-up: ↓ 11 Changed 2 years ago by rwaldron

@jitter,

I'm looking forward to seeing how this is handled.

comment:11 in reply to: ↑ 10 Changed 2 years ago by eamonn.kearns@…

Replying to rwaldron:

@jitter,

I'm looking forward to seeing how this is handled.

Likewise.

comment:12 Changed 2 years ago by rwaldron

  • Milestone changed from 1.5.1 to 1.next

comment:14 Changed 2 years ago by rkatic

A possible solution would be to limit which types are considered array-like in .makeArray(). These would be: arrays, jQuery objects, nodelists, and arguments.

 http://forum.jquery.com/topic/jquery-isarraylike-for-consistency#14737000002236285

Last edited 2 years ago by rkatic (previous) (diff)

comment:15 Changed 2 years ago by rkatic

 https://github.com/rkatic/jquery/compare/rkatic:master...%238104

I thing dropping support for array-like plain objects is not a big deal. It is not used internally. Not sure for the rest of the world.

Personally, I am not in favor of fixing this at all. But if needed...

Last edited 2 years ago by rkatic (previous) (diff)

comment:16 Changed 2 years ago by rkatic

After more testing, I realized that my patch fails with arguments objects. So ignore it.

comment:17 Changed 2 years ago by anonymous

I made some fixes to the patch. It's again available if wanted:  https://github.com/rkatic/jquery/compare/rkatic:master...%238104

comment:18 Changed 23 months ago by john

  • Status changed from open to closed
  • Resolution set to wontfix

Alright, we're not going to pursue this then.

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.