美文网首页
函数柯里化

函数柯里化

作者: ticktackkk | 来源:发表于2020-12-23 14:27 被阅读0次
var cost = (function () {
        var args = [];
        return function () {
          if (arguments.length === 0) {
            var money = 0;
            for (var i = 0; i < args.length; i++) {
              money += args[i];
            }
            console.log(money);
            return money;
          } else {
            [].push.apply(args, arguments);
            console.log(args);
          }
        };
      })();
      cost(100)
      cost(100)
      cost(100)
      cost()

相关文章

网友评论

      本文标题:函数柯里化

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