//toString机制
function add(number1){
var sum = number1;
var app = function(number2){
sum += number2;
return app;
};
app.toString = function(){
return sum;
}
return app;
}
alert(add(1)); // 1
console.log(add(1)(2)); // 3
console.log(add(1)(2)(3)); // 6
console.log(add(1)(2)(3)(4)); // 10
//柯里化函数
function sum(x){
function f(y){
return sum(x+y);
}
f.toString = f.valueOf = function(){
return x;
};
return f;
}
sum(1)(2)(3)
alert( (1) )
//不用循环打印
function print(str,number){
var arr = new Array( (number || 0) + 1 );
var str = arr.join(str);
alert(str)
}
print("helloword ",10);