I am learning JavaScript and I have learned recently about JavaScript timing events.
(我正在学习JavaScript,最近又了解了JavaScript计时事件。)
When I learned about setTimeout
at W3Schools , I noticed a strange figure which I didn't run into before.(当我在W3Schools了解了setTimeout
时,我注意到了一个我从未遇到过的奇怪数字。)
They are using double quotes and then call the function.(他们使用双引号,然后调用该函数。)
Example:
(例:)
setTimeout("alertMsg()", 3000);
I know that double and single quotes in JavaScript means a string.
(我知道JavaScript中的双引号和单引号表示字符串。)
Also I saw that I can do the same like that:
(我也看到我可以做同样的事情:)
setTimeout(alertMsg, 3000);
With the parentheses it's referring, without the parentheses it's copied.
(带有括号的是指,没有括号的是复制的。)
When I am using the quotes and the parentheses it's getting crazy.(当我使用引号和括号时,它越来越疯狂了。)
I will be glad if someone can explain to me the difference between these three ways of using setTimeout
:
(如果有人可以向我解释这三种使用setTimeout
方式之间的区别,我将感到非常高兴:)
With the parentheses:
(加上括号:)
setTimeout("alertMsg()", 3000);
Without the quotes and the parentheses:
(没有引号和括号:)
setTimeout(alertMsg, 3000);
And the third is only using quotes:
(第三只使用引号:)
setTimeout("alertMsg", 3000);
NB: A better source for setTimeout
reference would be MDN .
(注意: setTimeout
引用的更好来源是MDN 。)
ask by user1316123 translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…