Using Function.prototype.bind with an array of arguments?

后端 未结 10 1884
春和景丽
春和景丽 2020-12-08 01:57

How can I call Function.prototype.bind with an array of arguments, as opposed to hardcoded arguments? (Not using ECMA6, so no spread operator).

I\'m trying to put a

10条回答
  •  余生分开走
    2020-12-08 02:48

    For those using ES6, Babel compiles:

    db.find.bind(this, ...arguments)
    

    to:

    db.find.bind.apply(db.find, [this].concat(Array.prototype.slice.call(arguments)));
    

    I think it's fair to say Babel is pretty definitive. Credit to @lorenz-lo-sauer though, it's almost identical.

提交回复
热议问题