Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Make sure to do a deep copy on arrays. #5750
- Loading branch information
Showing
2 changed files
with
11 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0d1a2c1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am confused by the intention/implementation of this commit.
Iterating Arrays with for-in loops can produce different behaviors in older browsers. Is really
length
not-enumerable in every supported browser?.If
src
is an array, andcopy
is a plain object, then the current implementation will doextend(true, src, copy)
instead ofextend(true, {}, copy)
.Vice versa, if
src
is a plain object, andcopy
is an array, then the current implementation will doextend(true, src, copy)
instead ofextend(true, [], copy)
The test case at line 673 have no much sense - it do not evolving any deep extending.
0d1a2c1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am I the only one perceiving problems here?
0d1a2c1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rkatic.
The analysis you provided appears to be the intent of the author.
That
extend
method has no overview, comments, no formal parameters, is long, recursive, accepts variable number of optional "options" arguments and accepts an optionaldeep
argument as the first argument.Extra effort has gone into writing confusing, complicated code.
The first optional argument
deep
requires the function to perform conditional runtime behavior.Instead, the
extend
function should use formal parameters. This will help define what it does and will allow optimizing implementation to optimize the call whenarguments
is not in the function body.The boolean flag "deep" as an optional first argument is another complication. The
deep
parameter should acceptable as an optionallast
argument.Identifier
options
is the supplier of property values to copy totarget
.options
seem like a misleading name. It is not "options" but a supplier of properties totarget
.