LazyMan
class LazyMan { tasks = [] constructor(name){ this.name = name console.log(`I am ${name}`) setTimeout(() => { this.next() }) } next(){ const task = this.tasks.shift() if(task) task() } do(sth){ const task = () => { console.log(`do ${sth}`) this.next() } this.tasks.push(task) return this } sleep(delay){ const task = () => { setTimeout(() => { console.log(`sleep ${delay}s`) this.next() }, delay * 1000) } this.tasks.push(task) return this } }
以自己现在的努力程度,还没有资格和别人拼天赋