美文网首页
重复n次函数后失效

重复n次函数后失效

作者: 静候那一米阳光 | 来源:发表于2018-06-07 20:36 被阅读0次
    "use strict";
    function c() {
        console.log(1);
    }
    
    function repeat(fn, times) {
        fn.times = times;
        return function() {
            if (fn.times) {
                fn.times--;
                return fn();
            } else {
                throw "err";
            }
        }
    }
    var foo = repeat(c, 3);
    foo();
    foo();
    foo();
    foo();
    foo();
    foo();

    相关文章

      网友评论

          本文标题:重复n次函数后失效

          本文链接:https://www.haomeiwen.com/subject/sbsnsftx.html