Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function add(n) {
- if (typeof add.summ === "number") {
- add.summ += n;
- } else {
- add.summ = n
- };
- return add;
- }
- Function.prototype.toString = function () {
- var res = this.summ || "No sum";
- delete this.summ;
- return res;
- }
- alert( add(1) ) // выведет '1'
- alert( add(1)(9) ) // выведет '10'
- alert( add(4)(4)(4) ) // выведет '12'
Advertisement
Add Comment
Please, Sign In to add comment