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
c39bd07c
Commit
c39bd07c
authored
Jan 14, 2008
by
John Resig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added support for breaking in an object loop (Bug #2111).
parent
ff089825
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
7 deletions
+22
-7
core.js
src/core.js
+8
-6
core.js
test/unit/core.js
+14
-1
No files found.
src/core.js
View file @
c39bd07c
...
@@ -707,20 +707,22 @@ jQuery.extend({
...
@@ -707,20 +707,22 @@ jQuery.extend({
// args is for internal usage only
// args is for internal usage only
each
:
function
(
object
,
callback
,
args
)
{
each
:
function
(
object
,
callback
,
args
)
{
if
(
args
)
{
if
(
args
)
{
if
(
object
.
length
==
undefined
)
if
(
object
.
length
==
undefined
)
{
for
(
var
name
in
object
)
for
(
var
name
in
object
)
callback
.
apply
(
object
[
name
],
args
);
if
(
callback
.
apply
(
object
[
name
],
args
)
===
false
)
else
break
;
}
else
for
(
var
i
=
0
,
length
=
object
.
length
;
i
<
length
;
i
++
)
for
(
var
i
=
0
,
length
=
object
.
length
;
i
<
length
;
i
++
)
if
(
callback
.
apply
(
object
[
i
],
args
)
===
false
)
if
(
callback
.
apply
(
object
[
i
],
args
)
===
false
)
break
;
break
;
// A special, fast, case for the most common use of each
// A special, fast, case for the most common use of each
}
else
{
}
else
{
if
(
object
.
length
==
undefined
)
if
(
object
.
length
==
undefined
)
{
for
(
var
name
in
object
)
for
(
var
name
in
object
)
callback
.
call
(
object
[
name
],
name
,
object
[
name
]
);
if
(
callback
.
call
(
object
[
name
],
name
,
object
[
name
]
)
===
false
)
else
break
;
}
else
for
(
var
i
=
0
,
length
=
object
.
length
,
value
=
object
[
0
];
for
(
var
i
=
0
,
length
=
object
.
length
,
value
=
object
[
0
];
i
<
length
&&
callback
.
call
(
value
,
i
,
value
)
!==
false
;
value
=
object
[
++
i
]
){}
i
<
length
&&
callback
.
call
(
value
,
i
,
value
)
!==
false
;
value
=
object
[
++
i
]
){}
}
}
...
...
test/unit/core.js
View file @
c39bd07c
...
@@ -1314,7 +1314,7 @@ test("text(String)", function() {
...
@@ -1314,7 +1314,7 @@ test("text(String)", function() {
});
});
test
(
"$.each(Object,Function)"
,
function
()
{
test
(
"$.each(Object,Function)"
,
function
()
{
expect
(
8
);
expect
(
12
);
$
.
each
(
[
0
,
1
,
2
],
function
(
i
,
n
){
$
.
each
(
[
0
,
1
,
2
],
function
(
i
,
n
){
ok
(
i
==
n
,
"Check array iteration"
);
ok
(
i
==
n
,
"Check array iteration"
);
});
});
...
@@ -1326,6 +1326,19 @@ test("$.each(Object,Function)", function() {
...
@@ -1326,6 +1326,19 @@ test("$.each(Object,Function)", function() {
$
.
each
(
{
name
:
"name"
,
lang
:
"lang"
},
function
(
i
,
n
){
$
.
each
(
{
name
:
"name"
,
lang
:
"lang"
},
function
(
i
,
n
){
ok
(
i
==
n
,
"Check object iteration"
);
ok
(
i
==
n
,
"Check object iteration"
);
});
});
var
total
=
0
;
jQuery
.
each
([
1
,
2
,
3
],
function
(
i
,
v
){
total
+=
v
;
});
ok
(
total
==
6
,
"Looping over an array"
);
total
=
0
;
jQuery
.
each
([
1
,
2
,
3
],
function
(
i
,
v
){
total
+=
v
;
if
(
i
==
1
)
return
false
;
});
ok
(
total
==
3
,
"Looping over an array, with break"
);
total
=
0
;
jQuery
.
each
({
"a"
:
1
,
"b"
:
2
,
"c"
:
3
},
function
(
i
,
v
){
total
+=
v
;
});
ok
(
total
==
6
,
"Looping over an object"
);
total
=
0
;
jQuery
.
each
({
"a"
:
3
,
"b"
:
3
,
"c"
:
3
},
function
(
i
,
v
){
total
+=
v
;
return
false
;
});
ok
(
total
==
3
,
"Looping over an object, with break"
);
});
});
test
(
"$.prop"
,
function
()
{
test
(
"$.prop"
,
function
()
{
...
...
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