1.题目描述:
将数组 arr 中的元素作为调用函数 fn 的参数
输入:function (greeting, name, punctuation) {return greeting + ‘, ‘ + name + (punctuation || ‘!‘);}, [‘Hello‘, ‘Ellie‘, ‘!‘]
输出:Hello, Ellie!
解答:function argsAsArray(fn,arr){
return fn.apply(this,arr);
}
2.题目描述:
将函数 fn 的执行上下文改为 obj 对象
输入:function () {return this.greeting + ‘, ‘ + this.name + ‘!!!‘;}, {greeting: ‘Hello‘, name: ‘Rebecca‘}
输出:Hello, Rebecca!!!
解答:
function speak(fn, obj) {
return fn.apply(obj,arguments)
}
3.题目描述:
实现函数 functionFunction,调用之后满足如下条件:
1、返回值为一个函数 f
2、调用返回的函数 f,返回值为按照调用顺序的参数拼接,拼接字符为英文逗号加一个空格,即 ‘, ‘
3、所有函数的参数数量为 1,且均为 String 类型
输入:functionFunction(‘Hello‘)(‘world‘)
输出:Hello, world
解答:
function functionFunction(str) {
var f=function(str2){
if(typeof(str)=="string" && typeof(str2)=="string")
return str+‘, ‘+str2;
else return false;
};
return f;
}
剩余见https://blog.csdn.net/qq_24734285/article/details/50624342
原文:https://www.cnblogs.com/liyuanliu/p/9604892.html