闭包(2)

来源:互联网 发布:雪花飘落js特效代码 编辑:程序博客网 时间:2024/05/12 08:36

代码模式:闭包最强大的用途模块

<script>    function CoolModular(){        var something = "something";        var another = [1,2,3];        function doSomething()        {            console.log(something);        }        function doAnother()        {            console.log(another.join("!"));        }        return {            doSomething:doSomething,            doAnother:doAnother        }    }    var cool = CoolModular();    cool.doSomething();//something    cool.doAnother();//1!2!3!</script>
原创粉丝点击