面向对象编程,链式调用,先输出‘hello’,10秒之后,输出‘world’

let obj={
  awaitTime:null,
  consoleMsg:function(v){
    if(this.awaitTime){
      setTimeout(console.log(v),this.awaitTime*1000);
    }else{
      console.log(v)
    }
    return obj;
},
  awaitFn:function(time){
    this.awaitTime = time;
    return obj;
  }

}
obj.consoleMsg('hello').awaitFn(10).consoleMsg('world')

原文地址:https://www.cnblogs.com/-tao/p/8854527.html