-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprototype.js
More file actions
39 lines (39 loc) · 732 Bytes
/
Copy pathprototype.js
File metadata and controls
39 lines (39 loc) · 732 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
let LM = function (name) {
this.queue = []
this.cb = () => {
const fn = this.queue.shift()
fn && fn()
}
setTimeout(() => {
this.cb()
})
this.queue.push(() => {
console.log(`hi ${name}`)
this.cb()
})
}
LM.prototype = {
sleep (time) {
this.queue.push(() => {
setTimeout(this.cb, time * 1000)
})
return this
},
sleepFirst (time) {
this.queue.splice(0, 0, () => {
setTimeout(this.cb, time * 1000)
})
return this
},
eat (food) {
this.queue.push(() => {
console.log(`eat ${food}`)
this.cb()
})
return this
}
}
function LazyMan (name) {
return new LM(name)
}
LazyMan('alex').sleep(1).eat('😄').sleepFirst(2).sleep(2).eat('😭')