let index =0let stack =[]functionnext(){let fn = stack[index]
index++if(typeof fn ==='function'){fn()}}functionT(name){
stack.push(function(){
console.log('Hi! This is'+ name)next()})}functiontask(name){returnnewT(name)}T.prototype.sleep=function(delay){
stack.push(function(){setTimeout(()=>{
console.log('sleep have run end')next()},delay)})returnthis}T.prototype.eat=function(){
stack.push(function(){
console.log('eat have run end')next()})returnthis}task('zhangsan').sleep(1000).eat().sleep(1000).eat()next()