js closure4

var closure = (function(){
    var arr = [1, 3];
    function printArr() {
        console.log(arr);
    };

    return [arr, printArr];
}());


closure[1](); // [1, 3]
closure[0][1] = 2;
closure[1](); // [1, 2]

 

posted @ 2017-06-09 01:20  ax=null  阅读(117)  评论(0编辑  收藏  举报