Created
March 15, 2018 08:36
-
-
Save a1exlism/3f234a81852d7246cb52619c29e558d9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 题目要求! | |
* function repeat (func, times, wait) { | |
* } | |
* 这个函数能返回一个新函数,比如这样用 | |
* var repeatedFun = repeat(alert, 10, 5000) | |
* 调用这个 repeatedFun ("hellworld") | |
* 会alert十次 helloworld, `每次`间隔5秒 | |
*/ | |
function repeat( func, times, wait) { | |
if(times-- === 0) { | |
return ; | |
} | |
func('helloworld '); | |
setTimeout(function() { | |
repeat( func, times, wait); | |
}, wait); | |
} | |
var repeatedFun = repeat(console.log, 10, 1000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment