search

Home  >  Q&A  >  body text

javascript - js basic problem use of reduce

[].reduce.call('cbaacfdeaebb',function(p,n){ return p[n] = (p[n] || 0) 1,p; },{}),

I have seen such code, but I don’t quite understand how it works. Can reduce be applied to string through call? Are there any restrictions? How does it work? Can string be changed to other types? Such as map.
JS newbie, I hope the master can explain it in detail.

我想大声告诉你我想大声告诉你2751 days ago576

reply all(1)I'll reply

  • 仅有的幸福

    仅有的幸福2017-05-19 10:42:10

    JavaScript数组方法是特意定义为通用的,因此他们不仅应用在真正的数组而且在类数组对象上也能正确工作,但是类数组对象没有继承自Array.prototype,所以可以通过Function.callIndirectly called.

    And String can be used as an array-like object because it has a numeric length attribute and a corresponding non-negative integer attribute.

    reply
    0
  • Cancelreply