Advertisement
Guest User

Code Readability...

a guest
Jul 16th, 2016
1,712
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* From: http://stackoverflow.com/a/1280279/1175714
  2.  *
  3.  * This is an easier-to-read version that extrapolates
  4.  * from the very reasonable linux kernel coding style spec
  5.  * https://www.kernel.org/doc/Documentation/CodingStyle
  6.  *
  7.  * - Outer-most functions are treated as functions and get a next-line brace
  8.  * - Anything inside a function does not get a next-line brace.
  9.  * - 4-space indent
  10.  */
  11.  
  12. function setDeceleratingTimeout(callback, factor, times)
  13. {
  14.     var internalCallback = (function(tick, counter){
  15.         return function(){
  16.             if (--tick > 0) {
  17.                 window.settimeout(internalCallback, ++counter * factor);
  18.                 callback();
  19.             }
  20.         }
  21.     })(times, 0);
  22.  
  23.     window.setTimeout(internalCallback, factor);
  24. };
  25.  
  26. function test_setDeceleratingTimeout()
  27. {
  28.     function sayhi(){
  29.         console.log("hi");
  30.     }
  31.  
  32.     function saybye(){
  33.         console.log("bye");
  34.     }
  35.  
  36.     setDeceleratingTimeout(sayhi, 10, 10);
  37.     setDeceleratingTimeout(saybye, 100, 10);
  38. };
  39.  
  40. test_setDeceleratingTimeout();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement