kolesoffac

multi function

Mar 25th, 2018
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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'
Advertisement
Add Comment
Please, Sign In to add comment