闭包的练习题

// 闭包2道练习题

// 第1道

let foo = function(){
let i = 0;
return function(){
console.log(i++);
}
}
let f1 = foo();
let f2 = foo();
f1();// 0
f2();// 0
f1();// 1

// 第2道

let x = 100;
let y = 200;
let funA = function(x){
x += 1;
let y = 201;
let funB = function(){
console.log(x); // 102
console.log(y); // 201
}
return funB;
}
let f = funA(101);
f();
posted @ 2019-09-07 09:09  夜雨与你  阅读(1061)  评论(0编辑  收藏  举报