1. 程式人生 > >JavScript預編譯-變數提升和函式提升

JavScript預編譯-變數提升和函式提升

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script type="text/javascript">
        function fn(a) {
            console.log(a);

            var a = 123;

            console.log(a);

            function a () {}

            console.log(a);

            var b = function () {}

            console.log(b);

            function d () {}
        }

        fn(1);

        /*
        AO (Activate Object)物件
        AO{
            step1:          step2:               step3:               steps4(列印):
            a : undefined,  a : 1,               a : function () {}   function () {}
            b : undefined   b : undefined        b : undefined         123
                                                 d : function d () {}  123
                                                                      function () {}
            
        }

        預編譯四部曲:
            1.建立AO物件
            2.找形參和變數宣告,將變數和形參名作為AO屬性名,值為undefined
            3.將實參值和形參統一
            4.在函式體裡面找函式宣告,值賦予函式體
        */
    </script>

</body>

</html>