Why does Array.prototype.reduce not have a thisObject parameter?

后端 未结 3 1204
南方客
南方客 2020-12-31 04:49

Javascript Array methods such as forEach have a thisArg parameter, which is used as the context for invoking the callback:

array.fo         


        
3条回答
  •  天命终不由人
    2020-12-31 05:23

    You can always use this method :

    array.reduce(callback.bind(context), initialValue);
    

    ... in order to attach a specific context to the callback function.

提交回复
热议问题