<!DOCTYPE html>
<html>
<body>
<script>
function sampleDelay(delay) {
return function(functionArray) {
var count = 0;
var func = setInterval(function(){
if(count === functionArray.length){
clearInterval(func);
}
count++;
console.log(functionArray[count-1]);
return functionArray[count-1];
}, delay);
};
}
var DelayedValue = sampleDelay(1000)([
1,2,3,4,5
]);
</script>
</body>
</html>
我希望延迟一秒后将 DelayedValue 变量的值设为 1,2,3,4,5。此代码不返回 DelayedValue 变量的值。
请建议我做错了什么?