美文网首页
滴滴面试题

滴滴面试题

作者: 织雪纱奈 | 来源:发表于2019-08-26 17:05 被阅读0次
     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()
    

    相关文章

      网友评论

          本文标题:滴滴面试题

          本文链接:https://www.haomeiwen.com/subject/tledectx.html