You might also want to look at the already existing PeriodicalExecuter. Any implementation of a Function#repeat API should take this in account.
On Jun 24, 2:55 pm, "joe t." <thooke...@gmail.com> wrote: > Only suggestion i can think of is that your method strongly implies a > requirement that "repetitionsPollFn.repeat()" get assigned to a > variable so it can be cleared later: > > var interval = repetitiousPollFn.repeat(0.5); > // interval is the setInterval ID > > then later > window.clearInterval(interval); > > i could also see potential for more "scheduling" options > (repeatUntilTime, repeatXTimes, etc) built into your #repeat idea, but > don't really have the time to flesh them out. > > i find it an interesting idea though. :) > -joe t. > > On Jun 23, 11:25 am, Rick Waldron <waldron.r...@gmail.com> wrote: > > > > > I detest the way setInterval() looks, so I came up with this... have been > > using it my personal JS for some time. > > > Object.extend(Function.prototype, { > > repeat: function() { > > var __method = this, args = $A(arguments), interval = args.shift() * > > 1000; > > return window.setInterval(function() { > > return __method.apply(__method, args); > > }, interval ); > > } > > > }); > > > // usage: > > var _pollInt = 0; > > function repetiousPollFn() { > > console.log(_pollInt++); > > > } > > > repetiousPollFn.repeat(.5); > > > Will, of course, repeat repetiousPollFn() every half second. > > > Almost identical to .delay(), except that it returns setInterval instead of > > setTimeout. One thing I intend to add is support for clearInterval, however > > I figured I'd at least bring it up here first. I've never > > proposed/contributed here before (i'm a lurker of the list :D ) - any > > guidance is appreciated. > > > Rick --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Prototype: Core" group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to prototype-core-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~----------~----~----~----~------~----~------~--~---