minBy
"Let go of the thoughts that don't make you strong." —Unknown
本文为 《lodash 源码阅读》 系列文章,后续内容会在 github 中发布,欢迎 star,gitbook 同步更新。
依赖
源码
原理
minBy
使用 for...of
遍历 array
,这样做的好处是可以兼容自定义 Symbol.iterator
的 array
参数以及更多的类型(例如: String/TypeArray/Map/Set/arguments对象/DOM集合
等);再通过传入的 iteratee
方法取得当前值 current
,通过对 current
的类型判断,排除 null/undefinded/NaN/Symbol
情况,与缓存变量 computed
比对大小,最终计算返回正确的最大值结果。
Fix
阅读版本代码存在错误,已提 PR 进行修复.
相关链接
Last updated
Was this helpful?