<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title>高阶函数 实现sum(2)(3)</title>
    </head>
    <body>
        <script type="text/javascript">
            function add() {
                var args = [].slice.call(arguments);

                var fn = function() {
                    var arg_fn = [].slice.call(arguments);
                    return add.apply(null, args.concat(arg_fn));
                }

                fn.valueOf = function() {
                    return args.reduce((a, b) => a + b);
                }
                return fn;
            }
            let s = add(1)(2)(3);
            // function
            console.log(typeof s);
            // 6
            console.log(Number(s))
        </script>

    </body>
</html>

 

相关文章:

  • 2022-02-04
  • 2021-05-17
  • 2022-12-23
  • 2021-06-14
  • 2022-12-23
  • 2021-07-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-15
  • 2021-10-30
  • 2022-12-23
  • 2022-12-23
  • 2021-08-09
  • 2022-12-23
相关资源
相似解决方案