Tutorials Point

  Learn Prototype
  Prototype Resources
  Selected Reading

Copyright © 2014 by tutorialspoint

  Home     References     Discussion Forums     About TP  

Prototype Periodical Execution

previous next AddThis Social Bookmark Button


Many times it is required to execute a function many times after a certain period of time. For example, you may want to refresh your screen after a given time. Prototype provides a simple mechanism to implement it using PeriodicalExecuter object.

The advantage provided by PeriodicalExecuter is that it shields you against multiple parallel executions of the callback function.

Creating a PeriodicalExecuter:

The constructor takes two arguments:

  • The callback function.
  • The interval (in seconds) between executions.

Once launched, a PeriodicalExecuter triggers indefinitely, until the page unloads or the executer is stopped using stop() method.


Following is the example which will pop up a dialogue box after every 5 seconds untill you will stop it by pressing "cancel' button.

<title>Prototype examples</title>
   <script type="text/javascript" 

function startExec()
  new PeriodicalExecuter(function(pe) {
  if (!confirm('Want me to annoy you again later?'))
  }, 5);



  <p>Click start button to start periodic executer:</p>
  <br />

  <br />
  <input type="button" value="start" onclick="startExec();"/>


To understand it in better way you can Try it yourself.

previous next Printer Friendly