JavaScript partially applied function - How to bind only the 2nd parameter?

后端 未结 4 1256
忘掉有多难
忘掉有多难 2020-12-23 19:59

Sorry if I\'m missing something obvious, but I can\'t figure out how to bind a specific (nth) argument of a function in javascript. Most of my functional programming I\'ve

4条回答
  •  心在旅途
    2020-12-23 20:37

    Well. I'll just throw this out there.

    var add = function(a,b) {
      return a + b;
    };
    
    var addThree = function(a) {
      return add(a,3);
    };
    
    add(1,2);
    addThree(4);
    

    Maybe it will be ok for some.

提交回复
热议问题