How to bind function arguments without binding this?

前端 未结 15 913
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-30 07:25

In Javascript, how can I bind arguments to a function without binding the this parameter?

For example:

//Example function.
var c = funct         


        
15条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-30 07:50

    Using LoDash you can use the _.partial function.

    const f  = function (a, b, c, callback) {}
    
    const pf = _.partial(f, 1, 2, 3)  // f has first 3 arguments bound.
    
    pf(function () {})                // callback.
    

提交回复
热议问题