SOURCE

// var arr = [0,1]
// function fib(max){

//     var a = 0 ,b = 1;
//     while(arr.length < max){
//         [a, b] = [b, a + b];
//         arr.push(b);
//     }
//     return arr;
// }
// console.log(fib(4));
// console.log(fib(6));

function fibn(){
    var arr = [0,1]
    return function fib(max){
        var a = 0 ,b = 1;
        while(arr.length < max){
            [a, b] = [b, a + b];
            arr.push(b);
        }
        return arr;
    }
}
let f2 = fibn()
console.log(fibn()(8))
console.log(fibn()(4))
//必须给fibn一个引用  闭包才能生效

console.log(f2(8))
console.log(f2(4))

var f = function(){
    var num = 0;
    return function(){
        return num++
    }
}
var fn = f();
console.log(fn());
console.log(fn());
console.log(fn());
console.log(fn());
console.log('-------')
//引用fn与不引用的区别
console.log(f()())
console.log(f()())
console.log(f()())
console 命令行工具 X clear

                    
>
console