Bug Tracker

Opened 8 years ago

Closed 8 years ago

#9837 closed enhancement (cantfix)

Issue on extend (deep) with methods-properties

Reported by: tim.sebastian@… Owned by: Rick Waldron
Priority: low Milestone: 1.next
Component: core Version: 1.6.2
Keywords: Cc:
Blocked by: Blocking:

Description

A Deep Copy on an Object should run over Function(-Objects), too.

Right now the it behaves like this: http://jsfiddle.net/2ptQe/ If changing the Line 365 of Version 1.6.2 from this:

if ( deep && copy && ( jQuery.isPlainObject(copy) || (copyIsArray = jQuery.isArray(copy)) ) ){

to this:

if ( deep && copy && ( jQuery.isPlainObject(copy) || (copyIsArray = jQuery.isArray(copy)) || jQuery.isFunction(copy) ) ) {

it behaves more as expected: http://jsfiddle.net/GWtgU/

Change History (6)

comment:1 Changed 8 years ago by anonymous

sorry i forgot to state out, it concerns the "$.extend" function

comment:2 Changed 8 years ago by Rick Waldron

Component: unfiledcore
Owner: set to Rick Waldron
Priority: undecidedlow
Status: newassigned

comment:3 Changed 8 years ago by Rick Waldron

comment:4 Changed 8 years ago by Rick Waldron

The patch suggested above breaks the Core module of the test suite.

comment:5 Changed 8 years ago by tim.sebastian@…

Sorry, didnt check that. It seems almost impossible, since you cant(at least i cant) isolate a function from its properties, thus it will always be passed as a reference. Creating a closure would make it all too messy, and broke the test when trying to apply the properties again (ran into an endless loop on the jQuery.sub() test)

comment:6 Changed 8 years ago by dmethvin

Resolution: cantfix
Status: assignedclosed

I agree this is nigh-on impossible to do in a generic way on arbitrary objects. Basically $.extend() works fine for our use cases inside jQuery, using plain objects and primitive values. Some of the new ES5 features would help here, so maybe in another decade we can revisit. :)

Note: See TracTickets for help on using tickets.