Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
jquery
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
夏彬
jquery
Commits
694b625c
Commit
694b625c
authored
Jan 30, 2010
by
Robert Katic
Committed by
jeresig
Sep 23, 2010
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensured that arrays are not considered same as plain object on deep extending. Fixes #5991.
parent
2f603359
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
7 deletions
+11
-7
core.js
src/core.js
+10
-5
core.js
test/unit/core.js
+1
-2
No files found.
src/core.js
View file @
694b625c
...
@@ -306,7 +306,7 @@ jQuery.fn.init.prototype = jQuery.fn;
...
@@ -306,7 +306,7 @@ jQuery.fn.init.prototype = jQuery.fn;
jQuery
.
extend
=
jQuery
.
fn
.
extend
=
function
()
{
jQuery
.
extend
=
jQuery
.
fn
.
extend
=
function
()
{
// copy reference to target object
// copy reference to target object
var
target
=
arguments
[
0
]
||
{},
i
=
1
,
length
=
arguments
.
length
,
deep
=
false
,
options
,
name
,
src
,
copy
;
var
target
=
arguments
[
0
]
||
{},
i
=
1
,
length
=
arguments
.
length
,
deep
=
false
,
options
,
name
,
src
,
copy
,
copyIsArray
;
// Handle a deep copy situation
// Handle a deep copy situation
if
(
typeof
target
===
"boolean"
)
{
if
(
typeof
target
===
"boolean"
)
{
...
@@ -340,10 +340,15 @@ jQuery.extend = jQuery.fn.extend = function() {
...
@@ -340,10 +340,15 @@ jQuery.extend = jQuery.fn.extend = function() {
continue
;
continue
;
}
}
// Recurse if we're merging object literal values or arrays
// Recurse if we're merging plain objects or arrays
if
(
deep
&&
copy
&&
(
jQuery
.
isPlainObject
(
copy
)
||
jQuery
.
isArray
(
copy
)
)
)
{
if
(
deep
&&
copy
&&
(
jQuery
.
isPlainObject
(
copy
)
||
(
copyIsArray
=
jQuery
.
isArray
(
copy
))
)
)
{
var
clone
=
src
&&
(
jQuery
.
isPlainObject
(
src
)
||
jQuery
.
isArray
(
src
)
)
?
src
if
(
copyIsArray
)
{
:
jQuery
.
isArray
(
copy
)
?
[]
:
{};
copyIsArray
=
false
;
clone
=
src
&&
jQuery
.
isArray
(
src
)
?
src
:
[];
}
else
{
clone
=
src
&&
jQuery
.
isPlainObject
(
src
)
?
src
:
{};
}
// Never move original objects, clone them
// Never move original objects, clone them
target
[
name
]
=
jQuery
.
extend
(
deep
,
clone
,
copy
);
target
[
name
]
=
jQuery
.
extend
(
deep
,
clone
,
copy
);
...
...
test/unit/core.js
View file @
694b625c
...
@@ -661,7 +661,7 @@ test("jQuery.merge()", function() {
...
@@ -661,7 +661,7 @@ test("jQuery.merge()", function() {
});
});
test
(
"jQuery.extend(Object, Object)"
,
function
()
{
test
(
"jQuery.extend(Object, Object)"
,
function
()
{
expect
(
2
7
);
expect
(
2
6
);
var
settings
=
{
xnumber1
:
5
,
xnumber2
:
7
,
xstring1
:
"peter"
,
xstring2
:
"pan"
},
var
settings
=
{
xnumber1
:
5
,
xnumber2
:
7
,
xstring1
:
"peter"
,
xstring2
:
"pan"
},
options
=
{
xnumber2
:
1
,
xstring2
:
"x"
,
xxx
:
"newstring"
},
options
=
{
xnumber2
:
1
,
xstring2
:
"x"
,
xxx
:
"newstring"
},
...
@@ -688,7 +688,6 @@ test("jQuery.extend(Object, Object)", function() {
...
@@ -688,7 +688,6 @@ test("jQuery.extend(Object, Object)", function() {
same
(
deep2
.
foo
,
deep2copy
.
foo
,
"Check if not deep2: options must not be modified"
);
same
(
deep2
.
foo
,
deep2copy
.
foo
,
"Check if not deep2: options must not be modified"
);
equals
(
deep1
.
foo2
,
document
,
"Make sure that a deep clone was not attempted on the document"
);
equals
(
deep1
.
foo2
,
document
,
"Make sure that a deep clone was not attempted on the document"
);
ok
(
jQuery
.
extend
(
true
,
[],
arr
)
!==
arr
,
"Deep extend of array must clone array"
);
ok
(
jQuery
.
extend
(
true
,
{},
nestedarray
).
arr
!==
arr
,
"Deep extend of object must clone child array"
);
ok
(
jQuery
.
extend
(
true
,
{},
nestedarray
).
arr
!==
arr
,
"Deep extend of object must clone child array"
);
var
empty
=
{};
var
empty
=
{};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment