Change nameprint time to 100. setTimeout is not an async function.so it won't wait for printing John july anja.
(将名称打印时间更改为100。setTimeout不是异步函数。因此它不会等待打印John july anja。)
So you have to adjust your settimeout function time.Or you can use sleep function using ES6 Promise.(因此您必须调整settimeout函数的时间。也可以通过ES6 Promise使用睡眠功能。)
Every setimeout will create stack of functions to run which will run after time gets over.(每个setimeout将创建要运行的函数堆栈,这些函数将在时间结束后运行。)
See if this helps.(看看是否有帮助。)
function namePrint(name) {
return new Promise(resolve => {
setTimeout(() => {
console.log(name);
resolve();
}, 100);
});
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…