summaryrefslogtreecommitdiff
path: root/js/timers.ts
diff options
context:
space:
mode:
author迷渡 <justjavac@gmail.com>2019-07-18 18:09:32 +0800
committerRyan Dahl <ry@tinyclouds.org>2019-07-18 06:09:32 -0400
commitac98bd8a7ce13e6aaf35d13b8743281df24806d7 (patch)
tree87fb07b604fc2876341a881dd6562f466396764f /js/timers.ts
parenta0b8f13f18b24924d050e196baf6132b27a6011f (diff)
fix timer's params length (#2655)
Diffstat (limited to 'js/timers.ts')
-rw-r--r--js/timers.ts14
1 files changed, 10 insertions, 4 deletions
diff --git a/js/timers.ts b/js/timers.ts
index 7cac5cc6d..388827331 100644
--- a/js/timers.ts
+++ b/js/timers.ts
@@ -229,7 +229,7 @@ function setTimer(
/** Sets a timer which executes a function once after the timer expires. */
export function setTimeout(
cb: (...args: Args) => void,
- delay: number,
+ delay: number = 0,
...args: Args
): number {
// @ts-ignore
@@ -240,7 +240,7 @@ export function setTimeout(
/** Repeatedly calls a function , with a fixed time delay between each call. */
export function setInterval(
cb: (...args: Args) => void,
- delay: number,
+ delay: number = 0,
...args: Args
): number {
// @ts-ignore
@@ -261,10 +261,16 @@ function clearTimer(id: number): void {
idMap.delete(timer.id);
}
-export function clearTimeout(id: number): void {
+export function clearTimeout(id: number = 0): void {
+ if (id === 0) {
+ return;
+ }
clearTimer(id);
}
-export function clearInterval(id: number): void {
+export function clearInterval(id: number = 0): void {
+ if (id === 0) {
+ return;
+ }
clearTimer(id);
}