JavaScript, Node.js: is Array.forEach asynchronous?

后端 未结 10 1602
时光说笑
时光说笑 2020-11-22 10:47

I have a question regarding the native Array.forEach implementation of JavaScript: Does it behave asynchronously? For example, if I call:

[many          


        
10条回答
  •  深忆病人
    2020-11-22 11:53

    This is a short asynchronous function to use without requiring third party libs

    Array.prototype.each = function (iterator, callback) {
        var iterate = function () {
                pointer++;
                if (pointer >= this.length) {
                    callback();
                    return;
                }
                iterator.call(iterator, this[pointer], iterate, pointer);
        }.bind(this),
            pointer = -1;
        iterate(this);
    };
    

提交回复
热议问题