Home  >  Article  >  Web Front-end  >  JavaScript question, rewrite the function to add infinitely_javascript skills

JavaScript question, rewrite the function to add infinitely_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:56:16979browse

function add(x) {_______}; alert(add(2)(3)(4)); //Fill in the blanks so that the result is 9
Solution 1,

Copy code The code is as follows:

//貘大
function add(x) {
var c = 0;
return function(x) {
c = c x ; arguments.callee.toString = function(){
return c;
};
return arguments.callee;
}(x);
};
alert(add(2)(3)(4));

Solution 2,
Copy code The code is as follows:

//Sangui
function add(x) {
return function(y){
return function(z ){
return x y z;
}
}
};
alert(add(2)(3)(4));

Solution 3,
Copy code The code is as follows:

//Situ Zhengmei
function add (a) {
if(!isFinite(add.i)){
add.i = a
}else {
add.i = a;
}
add.valueOf = add .toString = function(){
return add.i
}
return add;
}
alert(add(2)(3)(4))

Actually, the above question is a curry test. Please see my other blog post for details.
If you have a different solution, please give me some advice!
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn