ivapopova

last_setTimeout_Example.html

Nov 17th, 2018
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Closure</title>
  5. <style type="text/css">
  6. .box{
  7. width: 200px;
  8. height: 200px;
  9. border: 1px solid #000;
  10. }
  11. </style>
  12. </head>
  13. <body>
  14. <div class="box"></div>
  15. <script type="text/javascript">
  16. colors = ['red', 'green', 'blue'];
  17. let box = document.querySelector('.box');
  18.  
  19. function changeColor(node, colors ){
  20. return function(){
  21. for(let i = 0; i<colors.length; i++){
  22. console.log(`i = ${i}`);
  23. node.style.backgroundColor= colors[i];
  24. }
  25. }
  26. }
  27.  
  28. setTimeout( changeColor(box, colors), 2000);
  29.  
  30. </script>
  31. </body>
  32. </html>
Advertisement
Add Comment
Please, Sign In to add comment