lgwebdream / FE-Interview

🔥🔥🔥 前端面试,独有前端面试题详解,前端面试刷题必备,1000+前端面试真题,Html、Css、JavaScript、Vue、React、Node、TypeScript、Webpack、算法、网络与安全、浏览器
https://lgwebdream.github.io/FE-Interview/
Other
6.76k stars 897 forks source link

return the two functions #1144

Closed geekftz closed 3 years ago

geekftz commented 3 years ago

function produce(fn, a, b) { var mySetInterVal, myClear; // 函数 var num = 0; // 起始值 var timer;

mySetInterVal = () => { timer = setTimeout(() => { fn(); num++; mySetInterVal(); }, a + num * b); };

myClear = () => { clearTimeout(timer); num = 0; };

return [mySetInterVal, myClear]; }

var loop = () => { console.log('loop called'); };

var [mySetInterVal, myClear] = produce(loop, 1000, 2000);