Bug Tracker

Modify

Ticket #5427 (closed bug)

Opened 4 years ago

Last modified 3 years ago

$.extend(false, target, obj) doesn't extend target itself

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

Description

After executing the following code:

var target = { a: 1 }; $.extend(false, target, { a: 2 });

target is still { a: 1 };

$.extend incorrectly finds target in its definition:

var target = arguments[0]
{}

Handle a deep copy situation

if ( typeof target === "boolean" ) {

deep = target;

target = arguments[1]
{};

skip the boolean and the target i = 2;

}

Change History

comment:1 Changed 4 years ago by gminuses

It has line-breaking issues, repost:

After executing the following code:

var target = { a: 1 }; $.extend(false, target, { a: 2 });

target is still { a: 1 };

$.extend incorrectly finds target in its definition:

var target = arguments[0] {}

// Handle a deep copy situation
if ( typeof target === "boolean" ) {

    deep = target;

    target = arguments[1] {}; 
    // skip the boolean and the target
    i = 2;

}

comment:2 Changed 4 years ago by gminuses

It can be easily fixed by just removing "|| {}":

var target = arguments[0], ...

The validation of target will be checked in its following code:

if ( typeof target !== "object" && !jQuery.isFunction(target) )
	target = {};

comment:3 Changed 3 years ago by rwaldron

  • Owner set to gminuses
  • Priority changed from major to low
  • Status changed from new to pending

Please distill this into a reduced test case on jsFiddle, thanks

comment:4 Changed 3 years ago by trac-o-bot

  • Status changed from pending to closed

Automatically closed due to 14 days of inactivity.

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.