首页 > setInterval 不写时间间隔时候的默认参数是多少?

setInterval 不写时间间隔时候的默认参数是多少?

  setInterval(function (){console.log(new Date().getMilliseconds())})

问题没实际意义.刚才手懒写漏了,发现不写间隔也能运行. 是有默认参数吗?


我们来翻官方文档:

If timeout is less than 10, then increase timeout to 10.

setInterval的timeout这个参数如果小于10就让它等于10

w3c:http://www.w3.org/TR/2011/WD-html5-20110525/timers.html#dom-windowtimers-setinterval

Displays a modal text field prompt with the given message, waits for
the user to dismiss it, and returns the value that the user entered.
If the user cancels the prompt, then returns null instead. If the
second argument is present, then the given value is used as a default.

blahblah一大堆我也不知道啥意思。大概就是说,如果没有值则为默认值
w3c:http://www.w3.org/TR/2011/WD-html5-20110525/timers.html#get-the-timeout


因此得出结论,如果没有传值,则为默认值,默认值为10,单位是毫秒


就是游览器执行完输出立即执行下一次执行,速度取决于游览器的执行速度

【热门文章】
【热门文章】