我对http://dreamerslab.com/blog/en/javascript-callbacks/中的示例感到困惑
function do_a(){
// simulate a time consuming function
setTimeout( function(){
console.log( '`do_a`: this takes longer than `do_b`' );
}, 1000 );
}
function do_b(){
console.log( '`do_b`: this is supposed to come out after `do_a` but it comes out before `do_a`' );
}
do_a();
do_b();
结果
`do_b`: this is supposed to come out after `do_a` but it comes out before `do_a`
`do_a`: this takes longer than `do_b`
而作者的解释是“然而javascript是一种事件驱动的语言。如果do_a比do_b花费的时间长,do_b的结果比do_a先出来;”。我还是不太清楚,请详细解释,或者请给我一些具体的材料,谢谢,