Bug Tracker


Opened 6 years ago

Closed 6 years ago

Last modified 5 years ago

#9994 closed enhancement (wontfix)

Optimization improvement in jQuery.extend

Reported by: anonymous Owned by: rwaldron
Priority: low Milestone:
Component: core Version: 1.6.2
Keywords: Cc:
Blocked by: Blocking:


On line 313 of core.js:


there is a check for:

typeof target === "boolean"

However, target has been set by:

target = arguments[0] || {},

so in case it's a boolean, it's always true (if arguments[0] was false, target is {}). Checking for true is much faster than a typeof check and then comparing strings, especially on IE:


Thanks for considering this optimization.

Change History (9)

comment:1 Changed 6 years ago by rwaldron

  • Component changed from unfiled to core
  • Milestone changed from None to 1.6.3
  • Owner set to rwaldron
  • Priority changed from undecided to low
  • Status changed from new to assigned
Last edited 6 years ago by rwaldron (previous) (diff)

comment:2 Changed 6 years ago by timmywil

Seems to me that this will not set the target correctly if both false and a target is passed to extend. That may not happen very often, but would be a regression.

$.extend( false, { some: "target" }, { more: "stuff" } );

comment:3 Changed 6 years ago by dmethvin

More often than I would have expected, that's fer sure.


There are probably more of the form $.extend(iCanHazDeep, defaults, options) but they're too hard to grep.

comment:4 Changed 6 years ago by rwaldron

If arguments[0] is any kind of falsy, it's not boolean by the time it reaches that condition.

comment:5 Changed 6 years ago by rwaldron

Sorry, by "it" I meant the target var

comment:6 Changed 6 years ago by rwaldron

  • Resolution set to wontfix
  • Status changed from assigned to closed

Turns out this is a performance hit, so no thanks.

comment:7 Changed 6 years ago by timmywil

This is now neither here nor there, but let me explain further. I don't think this would work anyway because target needs to get assigned to arguments[1] even if arguments[0] is false. It can't just be an empty plain object. The only place that happens is from within the typeof conditional, so it can't change unless that assignment is added somewhere else and at that point we're talking about changing more than just the conditional.

comment:8 Changed 6 years ago by dmethvin

  • Milestone 1.6.3 deleted

comment:9 Changed 5 years ago by rwaldron

#10867 is a duplicate of this ticket.

Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

Modify Ticket

Change Properties

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.