Skip to content

Commit 77ba623

Browse files
committed
Support passing extra arguments to setTimeout and setInterval
Closes marijnh#481
1 parent bdbd9e3 commit 77ba623

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

html/js/sandbox.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,20 @@
194194

195195
win.__setTimeout = win.setTimeout
196196
win.__setInterval = win.setInterval
197-
win.setTimeout = (code, time) => {
197+
win.setTimeout = (code, time, ...args) => {
198+
if (args.length && typeof code != "string") {
199+
let f = code
200+
code = () => f(...args)
201+
}
198202
let val = win.__setTimeout(() => this.run(code), time)
199203
this.timeouts.push(val)
200204
return val
201205
}
202-
win.setInterval = (code, time) => {
206+
win.setInterval = (code, time, ...args) => {
207+
if (args.length && typeof code != "string") {
208+
let f = code
209+
code = () => f(...args)
210+
}
203211
let val = win.__setInterval(() => this.run(code), time)
204212
this.intervals.push(val)
205213
return val

0 commit comments

Comments
 (0)