topical media & game development

talk show tell print

#javascript-code-13-closures.js / js



  // Find the element with an ID of 'main'
  var obj = document.getElementById("main");
  
  // Change it's border styling
  obj.style.border = "1px solid red";
  
  // Initialize a callback that will occur in one second
  setTimeout(function(){
      // Which will hide the object
      obj.style.display = 'none';
  }, 1000);
  
  // A generic function for displaying a delayed alert message
  function delayedAlert( msg, time ) {
      // Initialize an enclosed callback
      setTimeout(function(){
          // Which utilizes the msg passed in from the enclosing function
          alert( msg );
      }, time );
  }
  
  // Call the delayedAlert function with two arguments
  delayedAlert( "Welcome!", 2000 );
  
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.