【JavaScript手撕代码】sleep

function sleep(fn, wait=3*1000) {
    return new Promise((resolve, reject) => {
        setTimeout(() => {
            resolve(fn && fn())
        }, wait)
    })
}

【JavaScript手撕代码】sleep_第1张图片

你可能感兴趣的:(手撕JavaScript,javascript,面试,前端)