创建一个迭代器,接收任意多个函数参数
function nextRegister() {
var args = arguments;
var count = -1;
var comm = {};
function nextTime() {
count++;
if (count < args.length) {
if (args[count] && Object.prototype.toString.call(args[count]) == '[object Function]') {
args[count](comm, nextTime);
}
}
}
nextTime();
}
创建多个异步的函数,注入到迭代器中
/*
comm:多个函数,公用的变量
next:调用下一个函数
* */
function fn1(comm,next){
console.log('1');
comm.age = 20;
next();
}
function fn2(comm,next){
next();
console.log('2');
console.log(comm.age);
}
function fn3(comm,next){
console.log('3');
}
//开始执行迭代
nextRegister(fn1,fn2,fn3);
网友评论