Passing additional parameters in higher-order functions

前端 未结 6 1432
刺人心
刺人心 2020-12-13 11:01

Consider this example:



        
6条回答
  •  醉酒成梦
    2020-12-13 12:05

    You can use bind() to create a new function with the bound params;

    //you can replace the param with anything you like, null is for the context
    var excludeFoos = exclude.bind(null,"foos")
    const foos = samples.filter(excludeFoos);
    

    Live example here

提交回复
热议问题