javascript 闭包案例代码,及模拟私有变量。

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function ab1() {
            var a = 1;
            return {
                Abcr: function() {
                    return a;
                }
            };
        }

        var a1 = ab1();
        console.log(a1.Abcr());
    </script>
</body>

</html>

发表评论