You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
LazyMan('Tony');// Hi I am TonyLazyMan('Tony').sleep(10).eat('lunch');// Hi I am Tony// 等待了10秒...// I am eating lunchLazyMan('Tony').eat('lunch').sleep(10).eat('dinner');// Hi I am Tony// I am eating lunch// 等待了10秒...// I am eating dinerLazyMan('Tony').eat('lunch').eat('dinner').sleepFirst(5).sleep(10).eat('junk food');// Hi I am Tony// 等待了5秒...// I am eating lunch// I am eating dinner// 等待了10秒...// I am eating junk food
// 实现classlazyMan{constructor(name){this.name=namethis.sleepTime=0this.sleepFirstTime=0this.taskList=[]console.log(`Hi I am ${this.name}`);setTimeout(()=>{this.next()},0)}next(){varfn=this.taskList.shift();fn&&fn();}eat(f){varthat=this;varfn=(function(n){returnfunction(){console.log(`I am eating ${n}`)that.next();}})(name);this.taskList.push(fn);returnthis;}sleep(time){varthat=this;varfn=(function(t){returnfunction(){setTimeout(()=>{console.log(`等待了${t}秒...`)that.next();},t*1000);}})(time);this.taskList.push(fn);returnthis;}sleepFirst(time){varthat=this;varfn=(function(t){returnfunction(){setTimeout(()=>{console.log(`等待了${t}秒...`)that.next();},t*1000);}})(time);this.taskList.unshift(fn);returnthis;}}functionLazyMan(name){returnnewLazyManClass(name);}
The text was updated successfully, but these errors were encountered:
微信面试题 LazyMan
要求实现一个函数,需要满足以下功能
The text was updated successfully, but these errors were encountered: