View difference between Paste ID: 3vRaD7U8 and 0qUKacaF
SHOW: | | - or go back to the newest paste.
1-
function add() {
1+
function add(n) {
2
if (typeof add.summ === "number") {
3
	add.summ += n;
4
} else {
5
	add.summ = n
6
 };
7
8
 return add;
9
}
10
11
Function.prototype.toString = function () {
12
var res = this.summ || "No sum";
13
14
delete this.summ;
15
16
return res;
17
}
18
19
alert( add(1) ) // выведет '1'
20
alert( add(1)(9) ) // выведет '10'
21
alert( add(4)(4)(4) ) // выведет '12'