Can JavaScript function execution be interrupted?

前端 未结 3 1295
天命终不由人
天命终不由人 2020-12-10 08:58

Having an object to store data.

var store = {
    elements: [],
    eventsEnabled: true,
    addElement: function(element) {
        this.elements.push(eleme         


        
3条回答
  •  时光说笑
    2020-12-10 09:16

    JavaScript is single-threaded. A function cannot be interrupted, so you can be sure each function block will complete before another begins.

    (However, if a function makes an asynchronous call, other functions may execute before the asynchronous operation starts. That doesn't happen in your code, though, that I can see, besides the setTimeout calls, and you can be sure those will execute in the correct order.)

提交回复
热议问题