实现函数 functionFunction,调用之后满足如下条件:
1、返回值为一个函数 f
2、调用返回的函数 f,返回值为按照调用顺序的参数拼接,拼接字符为英文逗号加一个空格,即 ', '
3、所有函数的参数数量为 1,且均为 String 类型
functionFunction('Hello')('world')
Hello, world
functionFunction('Hello')('world')Hello, world
// 由于没有指定多少层函数就只能这样写了
function functionFunction(str) {
// 函数柯里化
return function(otherStr){
return `${str}, ${otherStr}`
}
} function joinString(str1, str2) {
// 只限两个数,
// 不支持
//functionFunction('Hello','world')
return [...arguments].join(', ');
}
function functionFunction(str) {
function _functionFunction(fn) {
let args = [];
let len = fn.length;
return function _c(...newArgs) {
args = [...args, ...newArgs]
if (args.length < len) {
return _c
} else {
//参数都接受完毕,打印
return fn.apply(this, args)
}
}
}
return _functionFunction(joinString)(str)
} function functionFunction(str) {
let f;
return (f = function (str2) {
return `${str}, ${str2}`
});
}