js 闭包演示

function test2()
                {
                    var scope = "global scope";
                    var f = enclose(scope);
                    scope = 'aaa';
                    alert(f());
                }
                
                function enclose(word)
                {
                    function f()
                    {
                        return word;
                    }
                    return f;
                }
                test2();

 

posted @ 2016-10-28 16:04  MvloveYouForever  阅读(166)  评论(1编辑  收藏  举报