Accessing an Internal Function in setInterval

Posted by Phonethics on Stack Overflow See other posts from Stack Overflow or by Phonethics
Published on 2010-05-04T10:34:48Z Indexed on 2010/05/04 10:38 UTC
Read the original article Hit count: 131

Filed under:
|
(function($)
{
    $.fn.myPlugin = function(options)
    {
        var _this;
        var timer1;

        var foo = function(n)
        {
            if (timer1 != null) return; // in action
            timer1 = setInterval("bar("+n+")", 500);
        };

        var bar = function(n)
        {
            ...
            if ( ... ) clearInterval(timer1);
        };                      

        return this.each(function()
        {
            _this = $(this);
            _this.bind("click", function(){ foo(10); });            
        });
    }
})(jQuery);

This doesn't work because "bar is not defined."

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about timers