Skip to content

Instantly share code, notes, and snippets.

@a1exlism
Created March 15, 2018 08:36
Show Gist options
  • Save a1exlism/3f234a81852d7246cb52619c29e558d9 to your computer and use it in GitHub Desktop.
Save a1exlism/3f234a81852d7246cb52619c29e558d9 to your computer and use it in GitHub Desktop.
/**
* 题目要求!
* 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