一、
请定义这样一个函数
function repeat (func, times, wait) {
}
这个函数能返回一个新函数,比如这样用
var repeatedFun = repeat(alert, 10, 5000)
调用这个 repeatedFun (“hellworld”)
会alert十次 helloworld, 每次间隔5秒
function repeat(func, times, wait) { function myRepeat() { var _arguments = arguments, i = 0; var handle = setInterval(function () { ++i; if (i === times) { clearInterval(handle); return; } func.apply(null,_arguments); },wait) } return myRepeat; } var repeatFun = repeat(alert,10,5000); repeatFun('hello world')
二、
写一个函数stringconcat, 要求能
var result1 = stringconcat(“a”, “b”) result1 = “a+b”
var stringconcatWithPrefix = stringconcat.prefix(“hellworld”);
var result2 = stringconcatWithPrefix(“a”, “b”) result2 = “hellworld+a+b”