Coder Social home page Coder Social logo

Comments (3)

hkongm avatar hkongm commented on May 6, 2024

例子可能不恰当,这种情况需要 出来。
通常下,当你的定时器里的代码,执行时间要大于你的第二个参数所设定的时间时,必然出现。
试着在一秒内,更新1000个DOM操作,再顺序执行这么几个定时器吧。

from jstutorial.

ystarlongzi avatar ystarlongzi commented on May 6, 2024

如果用户一直不点击“确定”,整个浏览器就处于“堵塞”状态,后面的执行就一直无法触发,将会累积起来

实际上如果你不点击『确定』按钮,后面的定时都会被 dropped 掉,而不是累加。所以这里描述的并不准确。还有这里关于 timer 运行机制 的描述

结果就是等到第二行语句运行完成以后,立刻连续输出三个2,然后开始每隔1000毫秒,输出一个2。也就是说,setIntervel具有累积效应,如果某个操作特别耗时,超过了setInterval的时间间隔,排在后面的操作会被累积起来,然后在很短的时间内连续触发

希望 @ruanyf 老师能修改下。

https://johnresig.com/blog/how-javascript-timers-work/
image

from jstutorial.

ruanyf avatar ruanyf commented on May 6, 2024

谢谢指出,已经更正。

from jstutorial.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.