Animations under single threaded JavaScript

前端 未结 4 662
既然无缘
既然无缘 2021-02-14 18:04

JavaScript is a single threaded language and therefore it executes one command at a time. Asynchronous programming is being implemented via Web APIs (DOM fo

4条回答
  •  有刺的猬
    2021-02-14 18:25

    You have several kind of functions in javascript: Blocking and non blocking.

    Non blocking function will return immediately and the event loop continues execution while it work in background waiting to call the callback function (like Ajax promises).

    Animation relies on setInterval and/or setTimeout and these two methods return immediately allowing code to resume. The callback is pushed back into the event loop stack, executed, and the main loop continues.

    Hope this'll help.

    You can have more information here or here

提交回复
热议问题