PromiseThen 横向代码编辑

it2022-05-11  66

var PromiseThen = function(){ var fns = []; this.then = function(fn){   fns.push(fn);   return this; } this.main = function (p){   var   //工序id   i = -1,   //是否停止   isStop = false;   //继续流程   resolve = function(o){     if( isStop ) return;     p = o;     i++;     fns[i] && fns[i].call({suc: resolve},p,resolve);   };   //触发第一道工序   resolve(p);   return this; } this.start = function(param){   //新建工序   return new this.main(); } //清除掉 this.remove = function(index){   if( !index ){     fns = [];   } } //插入工序 this.add = function(fn,index){   fns.splice(index,0,fn); }}

var b = new PromiseThen()//第一道工序.then(function(p,suc){ setTimeout(function(){ suc(); },5000) })//第二道工序.then(function(p,suc){ debugger; suc(); })//第三道工序.then(function(p,suc){ debugger; suc(); })//开始.start();

转载于:https://www.cnblogs.com/liao1992/p/10756995.html


最新回复(0)