added browser example
This commit is contained in:
parent
155d2c416c
commit
527d76dbd9
|
@ -0,0 +1,21 @@
|
|||
window.addEventListener('load', function () {
|
||||
'use strict';
|
||||
|
||||
function log() {
|
||||
document.querySelector('#foreach-console').innerHTML +=
|
||||
'\n' + Array.prototype.join.call(arguments, ' | ');
|
||||
console.log.apply(console, arguments);
|
||||
}
|
||||
|
||||
log('i', 'item', 'ms');
|
||||
[2, 11, 37, 42].forEach(function (item, i) {
|
||||
var ms = Math.floor(Math.random() * 1000)
|
||||
;
|
||||
|
||||
setTimeout(function () {
|
||||
log(i, item, ms);
|
||||
}, ms);
|
||||
});
|
||||
|
||||
log('All Done');
|
||||
});
|
|
@ -0,0 +1,25 @@
|
|||
window.addEventListener('load', function () {
|
||||
'use strict';
|
||||
|
||||
function log() {
|
||||
document.querySelector('#foreachasync-console').innerHTML +=
|
||||
'\n' + Array.prototype.join.call(arguments, ' | ');
|
||||
console.log.apply(console, arguments);
|
||||
}
|
||||
|
||||
var forEachAsync = window.forEachAsync
|
||||
;
|
||||
|
||||
log('i', 'item', 'ms');
|
||||
forEachAsync([2, 11, 37, 42], function (next, item, i) {
|
||||
var ms = Math.floor(Math.random() * 1000)
|
||||
;
|
||||
|
||||
setTimeout(function () {
|
||||
log(i, item, ms);
|
||||
next();
|
||||
}, ms);
|
||||
}).then(function () {
|
||||
log('All Done');
|
||||
});
|
||||
});
|
|
@ -0,0 +1,14 @@
|
|||
doctype html
|
||||
html
|
||||
head
|
||||
title forEachAsync example
|
||||
script(src="bower_components/forEachAsync/forEachAsync.js")
|
||||
script(src="foreach-settimeout.js")
|
||||
script(src="foreachasync-settimeout.js")
|
||||
body
|
||||
h1 Array.prototype.forEach
|
||||
code
|
||||
pre#foreach-console
|
||||
h1 forEachAsync
|
||||
code
|
||||
pre#foreachasync-console
|
Loading…
Reference in New Issue