Lodash _.find()函数的源代码位置在哪里?
Lodash find 函数相关说明
这是Lodash的find函数文档。
示例
var users = [ { 'user': 'barney', 'age': 36, 'active': true }, { 'user': 'fred', 'age': 40, 'active': false }, { 'user': 'pebbles', 'age': 1, 'active': true } ]; _.find(users, function(o) { return o.age < 40; }); // => object for 'barney' // The `_.matches` iteratee shorthand. _.find(users, { 'age': 1, 'active': true }); // => object for 'pebbles' // The `_.matchesProperty` iteratee shorthand. _.find(users, ['active', false]); // => object for 'fred' // The `_.property` iteratee shorthand. _.find(users, 'active'); // => object for 'barney
这是Lodash的GitHub仓库。
我尝试在该仓库中查找_.find()函数,但没有找到。它在哪里呢?
Lodash源码采用高度模块化设计,大量复用内部工具函数,_.find()的对应实现分布在这些文件中:
- 函数入口在
src/find.js,这里定义了对外暴露的_.find方法,会调用内部核心逻辑 - 核心查找逻辑由
src/internal/baseFind.js中的baseFind函数实现,同时还依赖src/internal/baseFindIndex.js等工具处理索引匹配逻辑
直接搜索_.find可能因为源码的模块化拆分找不到,但定位上述文件就能找到对应的实现代码。
内容的提问来源于stack exchange,提问作者Let Me Tink About It
相关产品推荐
相关产品推荐

