You can use setTimeout
to achieve a similar effect:
var a = 1 + 3;
var b;
setTimeout(function() {
b = a + 4;
}, (3 * 1000));
This doesn't really 'sleep' JavaScript—it just executes the function passed to setTimeout
after a certain duration (specified in milliseconds). Although it is possible to write a sleep function for JavaScript, it's best to use setTimeout
if possible as it doesn't freeze everything during the sleep period.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…