"too much recursion" in my rotating banner script

My rotating banner script throws an "too much recursion" error when a function iKeyless.widget.Rotator.rotate();is called internally init();. I cannot understand why it init();is called only once, and on the second call there is defer () when the page loads it before throwing "too much recursion"

    return {
        init: function () {
            ui.container = $("#rotating-banner");
            ui.thumbs = $("#rotating-banner .tabs .tab");
            ui.banners = $("#rotating-banner .banner");
            ui.fadeBox = $(".rotate .bd .fade-box");

            ui.thumbs.each(function (idx, el) {
                $(el).click(function () {
                    paused = true;

                    iKeyless.widget.Rotator.rotate.show(idx);
                });
            });

            iKeyless.widget.Rotator.rotate();
        },
        show: function (idx) {
            ui.fadeBox.css("display", "block");
            ui.fadeBox.animate({
                opacity: 1
            },
            .125,
            function () {
                $('.active', $(ui.banners[idx]).addClass('active').parent()).removeClass('active');

                ui.fadeBox.animate({
                    opacity: 1
                },
                .125,
                function () {
                    ui.fadeBox.css("display", "none");
                });
            });
        },
        rotate: function () {
            if (!paused) {
                this.show(counter);

                counter = counter + 1;

                if (counter === ui.thumbs.length) {
                    counter = 0;
                }

                iKeyless.widget.Rotator.rotate().defer(5000);
            }
        }
    }
+3
source share
3 answers

I think the problem is that you need to do this

iKeyless.widget.Rotator.rotate.defer(5000);

instead of this

iKeyless.widget.Rotator.rotate().defer(5000);

Source: When you write rotate (), you execute a function rotateand then execute defer. When you write rotate.defer (), you get the function rotateand using the method deferthat is defined in the function.

, jQuery, ? , jQuery . , , - . , delay. , ( 5 , 5000 ):

iKeyless.widget.Rotator.rotate.delay(5);
+1

, :

, .

, . . , , "" , .

, .

0

defer(), rotate() rotate, . , - setTimeout setInterval - ?

0

Source: https://habr.com/ru/post/1786435/


All Articles