javascript - js basic problem use of reduce
我想大声告诉你
我想大声告诉你 2017-05-19 10:40:10
0
1
556

[].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.

我想大声告诉你
我想大声告诉你

reply all(1)
仅有的幸福

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!