illegal use of break statement; javascript

前端 未结 3 1292
忘了有多久
忘了有多久 2021-02-06 21:09

When this variable becomes a certain amount i want the loop to stop, but i keep getting the error, \"Uncaught SyntaxError: Illegal break statement\".

function lo         


        
3条回答
  •  粉色の甜心
    2021-02-06 21:53

    I have a function next() which will maybe inspire you.

    function queue(target) {
            var array = Array.prototype;
    
            var queueing = [];
    
            target.queue = queue;
            target.queued = queued;
    
            return target;
    
            function queued(action) {
                return function () {
                    var self = this;
                    var args = arguments;
    
                    queue(function (next) {
                        action.apply(self, array.concat.apply(next, args));
                    });
                };
            }
    
            function queue(action) {
                if (!action) {
                    return;
                }
    
                queueing.push(action);
    
                if (queueing.length === 1) {
                    next();
                }
            }
    
            function next() {
                queueing[0](function (err) {
                    if (err) {
                        throw err;
                    }
    
                    queueing = queueing.slice(1);
    
                    if (queueing.length) {
                        next();
                    }
                });
            }
        }
    

提交回复
热议问题