今日一题:
实现一个after函数,接受俩个参数n和func,当他被被调用n或更多次的时候,将马上触发func.
function after(n,func){
var count = 0;
return function(){
count++;
if(count>n){
return func.apply(this,arguments);
}else{
console.log("after TODO");
}
}
}
let next = after(3,(msg)=>{
console.log(`已经调用了${
msg}次,需要停止`);
});
next(1);
next(2);
next(3);
next(4);
next(5);