Bug Tracker

Ticket #5427 (closed bug)

Opened 5 years ago

Last modified 4 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 5 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 5 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 4 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 4 years ago by trac-o-bot

  • Status changed from pending to closed

Automatically closed due to 14 days of inactivity.

Note: See TracTickets for help on using tickets.