<!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>