SOURCE

const lazyman = function (name) {
  console.log(name);
  return {
    executeChain: Promise.resolve(),
    eat,
    sleep
  }
};
 
const eat = function (food) {
  this.executeChain = this.executeChain.then(() => new Promise(resolve => {
    console.log(food);
    resolve();
  }))
  return this;
}
 
const sleep = function (time) {
  this.executeChain = this.executeChain.then(() => new Promise(resolve => {
    setTimeout(() => {
      resolve();
      console.log(time);
    }, time)
  }))
  return this;
}

lazyman('Jack').eat('lunch').sleep(1000).eat('dinner')
console 命令行工具 X clear

                    
>
console