From 0b943eea6483aebbaac6b510a0b52fdc8a6663a7 Mon Sep 17 00:00:00 2001 From: Leon Xu <6479451-leonxu260@users.noreply.gitlab.com> Date: Sat, 16 Oct 2021 22:45:19 -0700 Subject: [PATCH] doc: add common timer error section --- source/_posts/Timing.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/source/_posts/Timing.md b/source/_posts/Timing.md index 030e69b..49df26b 100644 --- a/source/_posts/Timing.md +++ b/source/_posts/Timing.md @@ -127,4 +127,16 @@ function multiply(a, b) { alert(a * b); } ``` -延迟之后的任何参数最终都会传递给计时器函数 \ No newline at end of file +延迟之后的任何参数最终都会传递给计时器函数 + +# 常见的计时器函数错误 +我们在开始写计时器函数的时候,有时候会错误的写了括号() +```javascript +~~setTimeout(sayHello(), 2000);~~ +setTimeout(sayHello, 2000); + +~~setTimeout(multiply(num1 * num2), 2000);~~ +setTimeout(multiply, 2000, num1, num2); +``` +那如果我们在setTimeout的时候写了括号在里面,它会发生什么? +- 它会立即调用函数,而不是等待2000毫秒! \ No newline at end of file