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
87ba780c
Commit
87ba780c
authored
Dec 06, 2009
by
John Resig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Renamed isObjectLiteral to isPlainObject (makes more sense, per the suggestion of Michael Geary).
parent
3c89e38f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
11 deletions
+11
-11
core.js
src/core.js
+3
-3
core.js
test/unit/core.js
+8
-8
No files found.
src/core.js
View file @
87ba780c
...
@@ -273,9 +273,9 @@ jQuery.extend = jQuery.fn.extend = function() {
...
@@ -273,9 +273,9 @@ jQuery.extend = jQuery.fn.extend = function() {
}
}
// Recurse if we're merging object literal values
// Recurse if we're merging object literal values
if
(
deep
&&
copy
&&
jQuery
.
is
ObjectLiteral
(
copy
)
)
{
if
(
deep
&&
copy
&&
jQuery
.
is
PlainObject
(
copy
)
)
{
// Don't extend not object literals
// Don't extend not object literals
var
clone
=
src
&&
jQuery
.
is
ObjectLiteral
(
src
)
?
src
:
{};
var
clone
=
src
&&
jQuery
.
is
PlainObject
(
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
);
...
@@ -314,7 +314,7 @@ jQuery.extend({
...
@@ -314,7 +314,7 @@ jQuery.extend({
return
toString
.
call
(
obj
)
===
"[object Array]"
;
return
toString
.
call
(
obj
)
===
"[object Array]"
;
},
},
is
ObjectLiteral
:
function
(
obj
)
{
is
PlainObject
:
function
(
obj
)
{
if
(
toString
.
call
(
obj
)
!==
"[object Object]"
||
typeof
obj
.
nodeType
===
"number"
)
{
if
(
toString
.
call
(
obj
)
!==
"[object Object]"
||
typeof
obj
.
nodeType
===
"number"
)
{
return
false
;
return
false
;
}
}
...
...
test/unit/core.js
View file @
87ba780c
...
@@ -200,41 +200,41 @@ test("trim", function() {
...
@@ -200,41 +200,41 @@ test("trim", function() {
equals
(
jQuery
.
trim
(
" "
+
nbsp
+
"hello "
+
nbsp
+
" "
),
"hello"
,
" "
);
equals
(
jQuery
.
trim
(
" "
+
nbsp
+
"hello "
+
nbsp
+
" "
),
"hello"
,
" "
);
});
});
test
(
"is
ObjectLiteral
"
,
function
()
{
test
(
"is
PlainObject
"
,
function
()
{
expect
(
7
);
expect
(
7
);
stop
();
stop
();
// The use case that we want to match
// The use case that we want to match
ok
(
jQuery
.
is
ObjectLiteral
({}),
"{}"
);
ok
(
jQuery
.
is
PlainObject
({}),
"{}"
);
// Instantiated objects shouldn't be matched
// Instantiated objects shouldn't be matched
ok
(
!
jQuery
.
is
ObjectLiteral
(
new
Date
),
"new Date"
);
ok
(
!
jQuery
.
is
PlainObject
(
new
Date
),
"new Date"
);
var
fn
=
function
(){};
var
fn
=
function
(){};
// Functions shouldn't be matched
// Functions shouldn't be matched
ok
(
!
jQuery
.
is
ObjectLiteral
(
fn
),
"fn"
);
ok
(
!
jQuery
.
is
PlainObject
(
fn
),
"fn"
);
// Again, instantiated objects shouldn't be matched
// Again, instantiated objects shouldn't be matched
ok
(
!
jQuery
.
is
ObjectLiteral
(
new
fn
),
"new fn (no methods)"
);
ok
(
!
jQuery
.
is
PlainObject
(
new
fn
),
"new fn (no methods)"
);
// Makes the function a little more realistic
// Makes the function a little more realistic
// (and harder to detect, incidentally)
// (and harder to detect, incidentally)
fn
.
prototype
=
{
someMethod
:
function
(){}};
fn
.
prototype
=
{
someMethod
:
function
(){}};
// Again, instantiated objects shouldn't be matched
// Again, instantiated objects shouldn't be matched
ok
(
!
jQuery
.
is
ObjectLiteral
(
new
fn
),
"new fn"
);
ok
(
!
jQuery
.
is
PlainObject
(
new
fn
),
"new fn"
);
// DOM Element
// DOM Element
ok
(
!
jQuery
.
is
ObjectLiteral
(
document
.
createElement
(
"div"
)),
"DOM Element"
);
ok
(
!
jQuery
.
is
PlainObject
(
document
.
createElement
(
"div"
)),
"DOM Element"
);
var
iframe
=
document
.
createElement
(
"iframe"
);
var
iframe
=
document
.
createElement
(
"iframe"
);
document
.
body
.
appendChild
(
iframe
);
document
.
body
.
appendChild
(
iframe
);
window
.
iframeDone
=
function
(
otherObject
){
window
.
iframeDone
=
function
(
otherObject
){
// Objects from other windows should be matched
// Objects from other windows should be matched
ok
(
jQuery
.
is
ObjectLiteral
(
new
otherObject
),
"new otherObject"
);
ok
(
jQuery
.
is
PlainObject
(
new
otherObject
),
"new otherObject"
);
document
.
body
.
removeChild
(
iframe
);
document
.
body
.
removeChild
(
iframe
);
start
();
start
();
};
};
...
...
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