class TaskLists {
constructor() {
this.middleware = []
}
add(fn, context, ...arg) {
this.middleware.push(fn.bind(context, ...arg))
}
compose (middleware) {
dispatch (0)
function dispatch (i) {
let fn = middleware[i]
fn(middleware[i+1]);
}
}
run() {
this.compose(this.middleware)
}
stop() {
}
}
let task = new TaskLists()
task.add(function(next){
console.log('我是first')
next()
})
task.add(function(){
console.log('我是second')
})
task.run()
网友评论