• Blogs (9)
    • 📱 236 - 992 - 3846

      📧 jxjwilliam@gmail.com

    • Version: ‍🚀 1.1.0
  • Function.prototype.toString custom

    Blogs20162016-12-23


    Function.prototype has methods like: call, apply, bind, toString etc. By overwrite them, we can custom the function input and output.Here is another good curry example:

    function multiply(a) {
      var res = a;
      return function mul(b) {
        res = res * b;
        Function.prototype.toString = function() {
          return res;
        }
        return mul;
      }
    }

    so the following work:

    multiply(2)(3)
    multiply(2)(3)(4)
    multiply(2)(3)(4)(8)(8)
    multiply(2)(9)(6)(22)(10)...