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

相关推荐

牛客251490824号:你这不去保研找鸡毛工作
点赞 评论 收藏
分享
小覃1:硕士了还投助理岗位吗,一般不都直接干工程师了吗
点赞 评论 收藏
分享
牛客网
牛客企业服务