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

后端 未结 10 1883
春和景丽
春和景丽 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:31

    If someone is looking for an abstract sample:

    var binded = hello.apply.bind(hello,null,['hello','world']);
    
    binded();
    
    function hello(a,b){
      console.log(this); //null
      console.log(a); //hello
      console.log(b); //world
    }
    

提交回复
热议问题