Re: How to use setInterval in google closure.

777 views
Skip to first unread message

Ross Dakin

unread,
Jul 12, 2012, 8:54:26 AM7/12/12
to closure-comp...@googlegroups.com
Please move topic to: https://groups.google.com/forum/?fromgroups#!forum/closure-library-discuss

On Thursday, July 12, 2012 1:27:58 AM UTC-7, Vinod wrote:
Hi Guys,
I need to use setInterval method in my application. I know that how to use it in the native script and jquery.But i dont know how to use it in closure.
Please help me out this.

Ross Dakin

unread,
Jul 12, 2012, 8:51:48 AM7/12/12
to closure-comp...@googlegroups.com
By the way, please ask questions about the Closure Library in its respective group (this group is specific to the Closure Compiler):

Thanks,
Ross

--
Ross Dakin
ross...@gmail.com
(858) 699-2190



On Thu, Jul 12, 2012 at 5:45 AM, Ross Dakin <ross...@gmail.com> wrote:
Hi Vinod,

You probably want goog.Timer, which differs a bit from window.setInterval primarily in that it dispatches events with each tick rather than invoking a single given callback:


A simple example:

    var timer = new goog.Timer(1000);
    timer.addEventListener(goog.Timer.TICK, function(e) {
        if (!confirm('Keep ticking?')) {
            e.target.dispose();
        }
    });
    timer.start();

For some higher-level classes that offer extended functionality, see:


Usage examples here:


Of course, you can always use the native window.<set|clear>Interval methods (which you should reference by full their full namespaces: http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml?showone=Explicit_scope#Explicit_scope), though you won't get the extra sugar.

Cheers,
Ross

Ross Dakin

unread,
Jul 12, 2012, 8:45:44 AM7/12/12
to closure-comp...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages