You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
functionbefore(n,func){letresultif(typeoffunc!=='function'){thrownewTypeError('Expected a function')}returnfunction(...args){if(--n>0){result=func.apply(this,args)}if(n<=1){func=undefined}console.log('result',result);returnresult}}functiononce(func){returnbefore(2,func)}constres=once((arg)=>arg);console.log('once',res(10));console.log('once',res(2));
Activity
luckept commentedon Jun 21, 2022
朴实无华版
baboon-king commentedon Jun 21, 2022
baboon-king commentedon Jun 21, 2022
卧槽卧槽!简直神之一手啊!
Rainer-Yu commentedon Jun 21, 2022
简单直接
Hongbusi commentedon Jun 21, 2022
可以实现,但是多了一个污染变量,还可以优化~
chenfan0 commentedon Jun 21, 2022
勉强实现
ChenHaoJie9527 commentedon Jun 21, 2022
闭包版
jp-liu commentedon Jun 21, 2022