es5之异步变同步
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>异步变同步</title> </head> <body> <script type="text/javascript"> var a = 0; window.onload = function(){ var a = function(){ setTimeout(function(){ a = 100; if(get){ get(a) } },5000) }() if(a){ document.write(a) }else if(!a){ var get = function(b){ a=b; document.write(a) } } } </script> </body> </html>