闭包的练习题

mac2022-06-30  81

// 闭包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();

转载于:https://www.cnblogs.com/yeyuyuni/p/11479181.html

最新回复(0)