function HardMan(str) { this.queue = [] this.name = str console.log(this.name) } HardMan.prototype.rest = function(wait) { const that = this const func = () => { setTimeout(() => { console.log(`Start learning after ${wait} seconds`) // debugger; that.next() }, wait * 1000) } this.queue.unshift(func) return this } HardMan.prototype.restFirst = function(wait) { const that = this const func = () => { setTimeout(() => { console.log(`Start learning after ${wait} seconds`) that.next() }, wait * 1000) } this.queue.unshift(func) return this } HardMan.prototype.learn = function(str) { const func = () => { console.log(str) } this.queue.push(func) this.next() } HardMan.prototype.next = function() { if(this.queue.length === 0) return const func = this.queue.shift() func() } 我感觉只能new 出来以后再用,直接用函数我也不会。。
2 3

相关推荐

牛客网
牛客企业服务