setTimeout runs twice after the first iteration

时间:2016-02-03 03:52:16

标签: javascript settimeout

    for (var i=0; i<sequence.length; i++) {
        allowclick=false;

        function playTimeout(n) {
            setTimeout(function() {
                _bubis[n].clicked();

            }, i*1000+750);
        }

        setTimeout(function(){allowclick=true},sequence.length*1000+750);

        playTimeout(sequence[i]);

        console.log(sequence);

    }

problem: I'm doing a Simon's game, and when the computer shows the sequence, it does the animation twice (_bubies.clicked()). It only happens when sequence.length is at least 2, and animtes twice regardless how long the sequence is.

0 个答案:

没有答案