Guest User

Untitled

a guest
Mar 23rd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. /**
  2. * 题目要求!
  3. * function repeat (func, times, wait) {
  4. * }
  5. * 这个函数能返回一个新函数,比如这样用
  6. * var repeatedFun = repeat(alert, 10, 5000)
  7.  
  8. * 调用这个 repeatedFun ("hellworld")
  9. * 会alert十次 helloworld, `每次`间隔5秒
  10. */
  11.  
  12. function repeat( func, times, wait) {
  13. if(times-- === 0) {
  14. return ;
  15. }
  16. func('helloworld ');
  17. setTimeout(function() {
  18. repeat( func, times, wait);
  19. }, wait);
  20. }
  21.  
  22.  
  23. var repeatedFun = repeat(console.log, 10, 1000)
Add Comment
Please, Sign In to add comment