Implement this function
person('tom')
// 输出 hi tom
person('tom').getup('洗刷刷')
// 输出 hi tom
// 输出 tom getup and 洗刷刷
person('tom').before('嘘嘘').getup('洗刷刷')
// 输出 tom 嘘嘘
// 输出 hi tom
// 输出 tom 嘘嘘 getup and 洗刷刷
Ask what to use to achieve? ?
The interviewer said that it involves asynchronous, queue, etc.~~~
It is a process control, just like lazyMan, you can see this http://www.cnblogs.com/Upton/...
I guess what you want is this. Here is a principle. The code structure is very simple
When there is an execution queue
jobs
调用before
的时候把内容加到队列头部 调用getup
, add the content to the endThe basic principle is to use the functions in
setTimeout
时间设置为0setTimeout
to be executed after everything in the current operating environment has been runSo I’m wondering if the third line of the question’s third example is output again
嘘嘘
Is it a typoBut even if it’s not a clerical error, it’s okay. According to this principle, you can change it however you want. It’s not a problem to call it multiple times
Refer to the promise implementation process