解法如下.
function count(x){
var fn = function(y){
return count(x*y);
}
fn.toString = function(){ // 前面的还好理解,关键是这句话。
return x;
};
return fn;
}
alert(count(1)(3)(5));//15
为什么之前返回都是一个函数的引用,但是最后一个参数传入后,方法返回一个数字?
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
主要还是因为
alert,如果是console.log就难说了 ..alert只能接受字符串参数,如果不是字符串,会自动调用toString()方法