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>

 

posted @ 2018-08-31 16:23  二月花开  阅读(2366)  评论(0编辑  收藏  举报