u.console("hello").settimeout(3000).console("world").settimeout(3000).console()
首先输出hello,3s后输出world,再间隔3s,再输出
这个我们可以使用累加定时来完成
function uc() {
this.arr = []
this.event = []
this.time = 0
this.console = function (str) {
if (this.event.length == 0) console.log(str)
else {
setTimeout(() => {
console.log(str)
}, this.event.shift())
}
return this
}
this.settimeout = function (time) {
this.time += time
this.event.push(this.time)
return this
}
}
let u = new uc()