Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* From: http://stackoverflow.com/a/1280279/1175714
- *
- * This is an easier-to-read version that extrapolates
- * from the very reasonable linux kernel coding style spec
- * https://www.kernel.org/doc/Documentation/CodingStyle
- *
- * - Outer-most functions are treated as functions and get a next-line brace
- * - Anything inside a function does not get a next-line brace.
- * - 4-space indent
- */
- function setDeceleratingTimeout(callback, factor, times)
- {
- var internalCallback = (function(tick, counter){
- return function(){
- if (--tick > 0) {
- window.settimeout(internalCallback, ++counter * factor);
- callback();
- }
- }
- })(times, 0);
- window.setTimeout(internalCallback, factor);
- };
- function test_setDeceleratingTimeout()
- {
- function sayhi(){
- console.log("hi");
- }
- function saybye(){
- console.log("bye");
- }
- setDeceleratingTimeout(sayhi, 10, 10);
- setDeceleratingTimeout(saybye, 100, 10);
- };
- test_setDeceleratingTimeout();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement