Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
John McEleney
/
casperjs
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit
f5adc45f
...
f5adc45fdd8d38acae29a03e7df213e99acda08d
authored
2013-10-21 11:42:19 +0200
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
refactored #each and #eachThen implementations
1 parent
064938ee
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
19 deletions
modules/casper.js
modules/casper.js
View file @
f5adc45
...
...
@@ -574,11 +574,11 @@ Casper.prototype.download = function download(url, targetPath, method, data) {
};
/**
* Iterates over the values of a provided array and execute a callback
*
for each
item.
* Iterates over the values of a provided array and execute a callback
for each
* item.
*
* @param Array array
* @param Function fn Callback: function(
self
, item, index)
* @param Function fn Callback: function(
casper
, item, index)
* @return Casper
*/
Casper
.
prototype
.
each
=
function
each
(
array
,
fn
)
{
...
...
@@ -587,17 +587,14 @@ Casper.prototype.each = function each(array, fn) {
this
.
log
(
"each() only works with arrays"
,
"error"
);
return
this
;
}
(
function
_each
(
self
)
{
array
.
forEach
(
function
_forEach
(
item
,
i
)
{
fn
.
call
(
self
,
self
,
item
,
i
);
});
})(
this
);
array
.
forEach
(
function
_forEach
(
item
,
i
)
{
fn
.
call
(
this
,
this
,
item
,
i
);
},
this
);
return
this
;
};
/**
* Iterates over the values of a provided array and adds a step
* for each item.
* Iterates over the values of a provided array and adds a step for each item.
*
* @param Array array
* @param Function then Step: function(response); item will be attached to response.data
...
...
@@ -606,18 +603,14 @@ Casper.prototype.each = function each(array, fn) {
Casper
.
prototype
.
eachThen
=
function
each
(
array
,
then
)
{
"use strict"
;
if
(
!
utils
.
isArray
(
array
))
{
this
.
log
(
"each() only works with arrays"
,
"error"
);
this
.
log
(
"each
Then
() only works with arrays"
,
"error"
);
return
this
;
}
(
function
_each
(
self
)
{
array
.
forEach
(
function
_forEach
(
item
,
i
)
{
self
.
then
(
function
()
{
this
.
then
(
this
.
createStep
(
then
,
{
data
:
item
}));
});
array
.
forEach
(
function
_forEach
(
item
)
{
this
.
then
(
function
()
{
this
.
then
(
this
.
createStep
(
then
,
{
data
:
item
}));
});
}
)(
this
);
}
,
this
);
return
this
;
};
...
...
Please
register
or
sign in
to post a comment