Bug Tracker

Modify

Ticket #4227 (closed bug: worksforme)

Opened 4 years ago

Last modified 3 years ago

$.extend erratic behavior with objects that have a length property

Reported by: dmethvin Owned by:
Priority: low Milestone: 1.4
Component: core Version: 1.3.2
Keywords: Cc:
Blocking: Blocked by:

Description

From the jQuery Google Group:  http://groups.google.com/group/jquery-en/browse_frm/thread/31e97b11082d2633#

Hello,

It seems that it's not safe to use "length" as a nested object property if I want to use jquery.extend. Is this a know issue?

$.extend(true, {},{"prop":{"length":"-1"}});

thanks,

-Morgan

Attachments

extend_object_with_length.patch Download (1.7 KB) - added by JDay 4 years ago.
Fix and testcase. Use jQuery.isArray() istead of checking for a length property.

Change History

Changed 4 years ago by JDay

Fix and testcase. Use jQuery.isArray() istead of checking for a length property.

comment:1 Changed 4 years ago by dmethvin

That would only handle true Array objects. I think the goal may have been to have $.extend be able to take array-like objects and treat them like Array, e.g., Function.arguments and DOM nodeList. It's worth thinking about so I'll leave the ticket open for further discussion.

comment:2 Changed 4 years ago by JDay

"Array-like" objects can still be handled and should work as before. Where is the value in making a "true" Array out of an object that wasn't an array to begin with?

comment:3 Changed 3 years ago by rwaldron

  • Status changed from new to closed
  • Resolution set to worksforme

Additional testing:

 http://jsfiddle.net/rwaldron/nqnBr/2/

I don't think there is any misbehaviour here. I'm closing, if the author wants to reopen, then we can do so with valid reason.

comment:4 Changed 3 years ago by rwaldron

  • Priority changed from minor to low

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.