Bug Tracker

Modify

Ticket #6675 (closed bug: fixed)

Opened 3 years ago

Last modified 3 years ago

makeArray fails on objects with a length property

Reported by: 314159abcde Owned by:
Priority: undecided Milestone: 1.4.3
Component: core Version: 1.4.2
Keywords: Cc:
Blocking: Blocked by:

Description

Try:

jQuery.makeArray( {'length':5} );

in the firebug console on any jQuery site and it will output [undefined, undefined, undefined, undefined, undefined]

when it should return [Object { length=5}]

This is causing issues where I have an object with a length and width attribute, since it will not pass through makeArray properly.

Change History

comment:1 Changed 3 years ago by Kiyoto

What is the expected behavior here? I changed line 650-652 of src/core.js to

else {

if ( type === "object" ) {

for ( var k in array ) {

push.call( ret, array[k] );

}

} else {

jQuery.merge( ret, array );

}

This will get the desired behavior for your case, but it breaks a slew of jQuery test cases. I was wondering what the expected behavior for jQuery.makeArray({'length':3}) was.

comment:2 Changed 3 years ago by Kiyoto

Never mind. I misread your post. Please scratch the previous comment

comment:3 Changed 3 years ago by addyosmani

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

As Kiyoto has already applied a patch for this to achieve the desired effect, I am updating this ticket to fixed. Please re-submit/re-open if required.

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.