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
990d9ca1
Commit
990d9ca1
authored
Nov 12, 2009
by
Robert Katic
Committed by
John Resig
Nov 12, 2009
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Made isObjectLiteral to work correctly with custom objects with empty prototypes.
parent
1ce92e02
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
3 deletions
+14
-3
core.js
src/core.js
+9
-2
core.js
test/unit/core.js
+5
-1
No files found.
src/core.js
View file @
990d9ca1
...
@@ -328,13 +328,20 @@ jQuery.extend({
...
@@ -328,13 +328,20 @@ jQuery.extend({
return
false
;
return
false
;
}
}
// not own constructor property must be Object
if
(
obj
.
constructor
&&
!
hasOwnProperty
.
call
(
obj
,
"constructor"
)
&&
!
hasOwnProperty
.
call
(
obj
.
constructor
.
prototype
,
"isPrototypeOf"
)
)
{
return
false
;
}
//own properties are iterated firstly,
//own properties are iterated firstly,
//so to speed up, we can test last one if it is own or not
//so to speed up, we can test last one if it is own or not
var
key
;
var
key
;
for
(
key
in
obj
)
{}
for
(
key
in
obj
)
{}
return
!
key
||
hasOwnProperty
.
call
(
obj
,
key
);
return
key
===
undefined
||
hasOwnProperty
.
call
(
obj
,
key
);
},
},
isEmptyObject
:
function
(
obj
)
{
isEmptyObject
:
function
(
obj
)
{
...
...
test/unit/core.js
View file @
990d9ca1
...
@@ -553,10 +553,14 @@ test("jQuery.extend(Object, Object)", function() {
...
@@ -553,10 +553,14 @@ test("jQuery.extend(Object, Object)", function() {
same
(
empty
.
foo
,
optionsWithDate
.
foo
,
"Dates copy correctly"
);
same
(
empty
.
foo
,
optionsWithDate
.
foo
,
"Dates copy correctly"
);
var
myKlass
=
function
()
{};
var
myKlass
=
function
()
{};
var
optionsWithCustomObject
=
{
foo
:
{
date
:
new
myKlass
}
};
empty
=
{};
jQuery
.
extend
(
true
,
empty
,
optionsWithCustomObject
);
same
(
empty
.
foo
,
optionsWithCustomObject
.
foo
,
"Custom objects copy correctly (no methods)"
);
// Makes the class a little more realistic
// Makes the class a little more realistic
myKlass
.
prototype
=
{
someMethod
:
function
(){}
};
myKlass
.
prototype
=
{
someMethod
:
function
(){}
};
empty
=
{};
empty
=
{};
var
optionsWithCustomObject
=
{
foo
:
{
date
:
new
myKlass
}
};
jQuery
.
extend
(
true
,
empty
,
optionsWithCustomObject
);
jQuery
.
extend
(
true
,
empty
,
optionsWithCustomObject
);
same
(
empty
.
foo
,
optionsWithCustomObject
.
foo
,
"Custom objects copy correctly"
);
same
(
empty
.
foo
,
optionsWithCustomObject
.
foo
,
"Custom objects copy correctly"
);
...
...
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