lodash 中文解析版
  • 介绍
  • Array(数组操作)
    • _.chunk(分块)
    • _.compact(过滤假值)
    • _.concat(连接)
    • _.difference(过滤值)
    • _.differenceBy(过滤值)
    • _.differenceWith(过滤值)
    • _.drop(开头丢掉n个元素)
    • _.dropRight(结尾丢掉n个元素)
    • _.dropRightWhile(结尾丢失元素)
    • _.dropWhile(开头丢掉元素)
    • _.fill(填充数组值)
    • _.findIndex(查找元素索引值)
    • _.findLastIndex(查找元素的索引值)
    • _.first -> head(取数组第一个元素)
    • _.flatten(减少一层嵌套)
    • _.flattenDeep(递归为一维数组)
    • _.flattenDepth(减少depth层嵌套)
    • _.fromPairs(返回键值对对象)
    • _.indexOf(获取元素的索引值)
    • _.initial(去除最后一个元素)
    • _.intersection(数组交集)
    • _.intersectionBy(数组交集)
    • _.intersectionWith(数组交集)
    • _.join(转字符串,类php-implode)
    • _.last(获取最后一个元素)
    • _.lastIndexOf(获取元素的索引值)
    • _.nth(获取元素的值)
    • _.pull(删除数组中元素)
    • _.pullAll(删除数组中元素)
    • _.pullAllBy(删除数组中的元素)
    • _.pullAllWith(删除数组中的元素)
    • _.pullAt(删除数组中的元素)
    • _.remove(删除数组中的元素)
    • _.reverse(元素位置反转)
    • _.slice(数组截取)
    • _.sortedIndex(获取索引值)
    • _.sortedIndexBy(获取索引值)
    • _.sortedIndexOf(获取索引值)
    • _.sortedLastIndex(获取索引值)
    • _.sortedLastIndexBy(获取索引值)
    • _.sortedLastIndexOf(获取索引值)
    • _.sortedUniq(数组去重)
    • _.sortedUniqBy(数组去重)
    • _.tail(除最后元素的数组)
    • _.take(数组截取)
    • _.takeRight(数组截取)
    • _.takeRightWhile(数组截取)
    • _.takeWhile(数组截取)
    • _.union(数组合并)
    • _.unionBy(数组合并)
    • _.unionWith(数组合并)
    • _.uniq(数组去重)
    • _.uniqBy(数组去重)
    • _.uniqWith(数组去重)
    • _.unzip(数组重组)
    • _.unzipWith(数组重组)
    • _.without(过滤元素值)
    • _.xor(数组取差集)
    • _.xorBy(数组取差集)
    • _.xorWith(数组取差集)
    • _.zip(数组重组)
    • _.zipObject(返回键值对新数组)
    • _.zipObjectDeep(返回键值对新数组)
    • _.zipWith(数组重组)
  • Collection(集合操作)
    • _.countBy(迭代处理数组或对象中的值)
    • _.each -> forEach(遍历数组或对象)
    • _.eachRight -> forEachRight
    • _.every(断言数组或对象中的值)
    • _.filter(过滤数组或者对象)
    • _.find(查找数组或对象中符合条件的值)
    • _.findLast(查找数组或对象中符合条件的值)
    • _.flatMap(创建同阶数组)
    • _.flatMapDeep(创建同阶数组)
    • _.flatMapDepth(创建同阶数组)
    • _.forEach(遍历数组或对象)
    • _.forEachRight(从右到左遍历数组或对象)
    • _.groupBy(遍历处理数组或对象元素值)
    • _.includes(检查值是否在数组/对象/字符串中)
    • _.invokeMap
    • _.keyBy(遍历处理数组或对象元素值)
    • _.map(迭代遍历处理数组或对象元素)
    • _.orderBy(数组或对象元素值排序)
    • _.partition(数组或对象断言分组)
    • _.reduce(数组或对象迭代累加后的结果)
    • _.reduceRight(数组或对象迭代累加后的结果)
    • _.reject(_.filter的反向方法)
    • _.sample(从对象或数组中获得一个随机元素)
    • _.sampleSize(从对象或数组中获得n个随机元素)
    • _.shuffle(创建一个被打乱的数组集合)
    • _.size(返回数组或对象的长度)
    • _.some(迭代断言函数,遇true停)
    • _.sortBy(数组或对象排序)
  • Date(日期操作)
    • _.now(时间戳)
  • Function(操作函数)
    • _.after(n次后出发某个函数)
    • _.ary
    • _.before
    • _.bind
    • _.bindKey
    • _.curry
    • _.curryRight
    • _.debounce
    • _.defer
    • _.delay
    • _.flip
    • _.memoize
    • _.negate
    • _.once
    • _.overArgs
    • _.partial
    • _.partialRight
    • _.rearg
    • _.rest
    • _.spread
    • _.throttle
    • _.unary
    • _.wrap
  • Lang(类型转换与类型判断操作)
    • _.castArray(强转成数组)
    • _.clone(数据的浅克隆)
    • _.cloneDeep(数据的深克隆)
    • _.cloneDeepWith(数据的深克隆)
    • _.cloneWith(数据的浅克隆)
    • _.conformsTo(对象断言判断)
    • _.eq(两值是否相等)
    • _.gt(是否大于某值)
    • _.gte(是否大于等于某值)
    • _.isArguments(是否是arguments对象)
    • _.isArray(是否是数组)
    • _.isArrayBuffer(是否是ArrayBuffer对象)
    • _.isArrayLike(是否是类数组)
    • _.isArrayLikeObject(是否是类对象数组)
    • _.isBoolean(是否是boolean类型)
    • _.isBuffer(是否是个 buffer)
    • _.isDate(是否是Date对象)
    • _.isElement(是否是DOM元素)
    • _.isEmpty(是否为空)
    • _.isEqual(两值是否相等)
    • _.isEqualWith(两值是否相等)
    • _.isError(是否是Error相关对象)
    • _.isFinite(是否是有限数值)
    • _.isFunction(是否是Function对象)
    • _.isInteger(是否是整数)
    • _.isLength(是否为有效的类数组长度)
    • _.isMap(是否是Map对象)
    • _.isMatch(是否匹配给定的值)
    • _.isMatchWith(是否匹配给定值)
    • _.isNaN(是否是NaN值)
    • _.isNative(是否是原生函数)
    • _.isNil(是否是null或者undefined)
    • _.isNull(是否为null)
    • _.isNumber(是否是数值)
    • _.isObject(是否是对象)
    • _.isObjectLike(是否是类对象)
    • _.isPlainObject(是否是普通对象)
    • _.isRegExp(是否为RegExp对象)
    • _.isSafeInteger(是否是安全整数)
    • _.isSet(是否为Set对象)
    • _.isString(是否为字符串)
    • _.isSymbol(是否为Symbol对象)
    • _.isTypedArray(是否为是否是TypedArray对象)
    • _.isUndefined(是否为undefined)
    • _.isWeakMap(是否为WeakMap对象)
    • _.isWeakSet(是否为WeakSet对象)
    • _.lt(两值比较小于)
    • _.lte(两值比较小于等于)
    • _.toArray(强转为数组)
    • _.toFinite(强转为有限数字)
    • _.toInteger(强转为整数)
    • _.toLength(强转为整数)
    • _.toNumber(强转为数字)
    • _.toPlainObject(强转为普通对象)
    • _.toSafeInteger(强转为安全整数)
    • _.toString(强转为字符串)
  • Math(数学操作)
    • _.add(两个数求和)
    • _.ceil(向上舍入)
    • _.divide(两个数相除)
    • _.floor(向下舍入)
    • _.max(取数组中最大值)
    • _.maxBy(取数组中最大值)
    • _.mean(求数组中值平均值)
    • _.meanBy(求数组中值平均值)
    • _.min(取数组中最小值)
    • _.minBy(取数组中最小值)
    • _.multiply(两数相乘求积)
    • _.round(四舍五入)
    • _.subtract(两数相减求差)
    • _.sum(求数组中值总和)
    • _.sumBy(求数组中值总和)
  • Number(数值操作)
    • _.clamp(求夹值)
    • _.inRange(判断值是否在区间内)
    • _.random(获取随机数)
  • Object(对象操作)
    • _.assign
    • _.assignIn
    • _.assignInWith
    • _.assignWith
    • _.at
    • _.create
    • _.defaults
    • _.defaultsDeep
    • _.entries -> toPairs
    • _.entriesIn -> toPairsIn
    • _.extend -> assignIn
    • _.extendWith -> assignInWith
    • _.findKey
    • _.findLastKey
    • _.forIn
    • _.forInRight
    • _.forOwn
    • _.forOwnRight
    • _.functions
    • _.functionsIn
    • _.get
    • _.has
    • _.hasIn
    • _.invert
    • _.invertBy
    • _.invoke
    • _.keys
    • _.keysIn
    • _.mapKeys
    • _.mapValues
    • _.merge
    • _.mergeWith
    • _.omit
    • _.pick
    • _.pickBy
    • _.result
    • _.set
    • _.setWith
    • _.toPairs
    • _.toPairsIn
    • _.transform
    • _.unset
    • _.update
    • _.updateWith
    • _.values
    • _.valuesIn
  • Seq
    • _
    • _.chain
    • _.tap
    • _.thru
    • _.prototype[Symbol.iterator]
    • _.prototype.at
    • _.prototype.chain
    • _.prototype.commit
    • _.prototype.next
    • _.prototype.plant
    • _.prototype.reverse
    • _.prototype.toJSON -> value
    • _.prototype.value
    • _.prototype.valueOf -> value
  • String(字符串操作)
    • _.camelCase(转驼峰)
    • _.capitalize(首字母大写其他小写)
    • _.deburr(拉丁语字母处理)
    • _.endsWith(检测结尾字符串)
    • _.escape(转html实体字符)
    • _.escapeRegExp(转义正则特殊字符)
    • _.kebabCase(以-连接字符串)
    • _.lowerCase(空格分开单词并转小写)
    • _.lowerFirst(仅首字母小写其他不变)
    • _.pad(左右填充字符)
    • _.padEnd(右侧填充字符)
    • _.padStart(左侧填充字符)
    • _.parseInt(转成不同进制整数)
    • _.repeat(重复给定字符串)
    • _.replace(字符串替换)
    • _.snakeCase(以下划线_连接字符串)
    • _.split(拆分字符串为数组)
    • _.startCase(空格间隔的首字母大写单词)
    • _.startsWith(检查开头字符串)
    • _.template(创建预编译模板方法)
    • _.toLower(字符串转小写)
    • _.toUpper(字符串转大写)
    • _.trim(移除两侧空格或指定字符)
    • _.trimEnd(移除尾部空格或指定字符)
    • _.trimStart(移除头部空格或指定字符)
    • _.truncate(截断字符串)
    • _.unescape(转实体为对应字符)
    • _.upperCase(空格分隔的大写单词)
    • _.upperFirst(仅首字母大写其他不变)
    • _.words(拆分字符串为数组)
  • Util(工具方法)
    • _.attempt
    • _.bindAll
    • _.cond
    • _.conforms
    • _.constant
    • _.defaultTo
    • _.flow
    • _.flowRight
    • _.identity
    • _.iteratee
    • _.matches
    • _.matchesProperty
    • _.method
    • _.methodOf
    • _.mixin
    • _.noConflict
    • _.noop
    • _.nthArg
    • _.over
    • _.overEvery
    • _.overSome
    • _.property
    • _.propertyOf
    • _.range
    • _.rangeRight
    • _.runInContext
    • _.stubArray
    • _.stubFalse
    • _.stubObject
    • _.stubString
    • _.stubTrue
    • _.times
    • _.toPath
    • _.uniqueId
  • Properties(略,不常用)
  • Methods(略,不常用)
  • SUMMARY
  • 附录:资料
Powered by GitBook
On this page

Was this helpful?

  1. Seq

_

PreviousSeqNext_.chain

Last updated 5 years ago

Was this helpful?

语法:

_(value)

描述:

创建一个lodash对象,包装value后的对象启用隐式方法链。返回的数组、集合、方法相互之间能够链式调用。检索唯一值或返回原始值会自动解除链条并返回计算后的值,否则需要调用_#value方法解除链(即获得计算结果)。 显式链式调用,在任何情况下需要先用_#value解除链后,才能使用开启。

链式方法是惰性计算的,直到隐式或者显式调用了_#value才会执行计算。

惰性计算接受几种支持 shortcut fusion 的方法, shortcut fusion 是一种通过合并链式 iteratee 调用从而大大降低迭代的次数以提高执行性能的方式。 部分链有资格 shortcut fusion,如果它至少有超过200个元素的数组和任何只接受一个参数的 iteratees。 触发的方式是任何一个 shortcut fusion 有了变化。

链式方法支持定制版本,只要 _#value 包含或者间接包含在版本中。

除了 lodash 的自身方法,包装后的对象还支持 Array 和 String 的方法。

支持 Array 的方法: concat, join, pop, push, shift, sort, splice, 和 unshift

支持 String 的方法: replace 和 split

支持 shortcut fusion 的方法: at, compact, drop, dropRight, dropWhile, filter, find, findLast, head, initial, last, map, reject, reverse, slice, tail, take, takeRight, takeRightWhile, takeWhile, 和 toArray

支持 链式调用 的方法: after, ary, assign, assignIn, assignInWith, assignWith, at, before, bind, bindAll, bindKey, castArray, chain, chunk, commit, compact, concat, conforms, constant, countBy, create, curry, debounce, defaults, defaultsDeep, defer, delay, difference, differenceBy, differenceWith, drop, dropRight, dropRightWhile, dropWhile, extend, extendWith, fill, filter, flatMap, flatMapDeep, flatMapDepth, flatten, flattenDeep, flattenDepth, flip, flow, flowRight, fromPairs, functions, functionsIn, groupBy, initial, intersection, intersectionBy, intersectionWith, invert, invertBy, invokeMap, iteratee, keyBy, keys, keysIn, map, mapKeys, mapValues, matches, matchesProperty, memoize, merge, mergeWith, method, methodOf, mixin, negate, nthArg, omit, omitBy, once, orderBy, over, overArgs, overEvery, overSome, partial, partialRight, partition, pick, pickBy, plant, property, propertyOf, pull, pullAll, pullAllBy, pullAllWith, pullAt, push, range, rangeRight, rearg, reject, remove, rest, reverse, sampleSize, set, setWith, shuffle, slice, sort, sortBy, splice, spread, tail, take, takeRight, takeRightWhile, takeWhile, tap, throttle, thru, toArray, toPairs, toPairsIn, toPath, toPlainObject, transform, unary, union, unionBy, unionWith, uniq, uniqBy, uniqWith, unset, unshift, unzip, unzipWith, update, updateWith, values, valuesIn, without, wrap, xor, xorBy, xorWith, zip, zipObject, zipObjectDeep, and zipWith

默认 不 支持 链式调用 的方法: add, attempt, camelCase, capitalize, ceil, clamp, clone, cloneDeep, cloneDeepWith, cloneWith, conformsTo, deburr, defaultTo, divide, each, eachRight, endsWith, eq, escape, escapeRegExp, every, find, findIndex, findKey, findLast, findLastIndex, findLastKey, first, floor, forEach, forEachRight, forIn, forInRight, forOwn, forOwnRight, get, gt, gte, has, hasIn, head, identity, includes, indexOf, inRange, invoke, isArguments, isArray, isArrayBuffer, isArrayLike, isArrayLikeObject, isBoolean, isBuffer, isDate, isElement, isEmpty, isEqual, isEqualWith, isError, isFinite, isFunction, isInteger, isLength, isMap, isMatch, isMatchWith, isNaN, isNative, isNil, isNull, isNumber, isObject, isObjectLike, isPlainObject, isRegExp, isSafeInteger, isSet, isString, isUndefined, isTypedArray, isWeakMap, isWeakSet, join, kebabCase, last, lastIndexOf, lowerCase, lowerFirst, lt, lte, max, maxBy, mean, meanBy, min, minBy, multiply, noConflict, noop, now, nth, pad, padEnd, padStart, parseInt, pop, random, reduce, reduceRight, repeat, result, round, runInContext, sample, shift, size, snakeCase, some, sortedIndex, sortedIndexBy, sortedLastIndex, sortedLastIndexBy, startCase, startsWith, stubArray, stubFalse, stubObject, stubString, stubTrue, subtract, sum, sumBy, template, times, toFinite, toInteger, toJSON, toLength, toLower, toNumber, toSafeInteger, toString, toUpper, trim, trimEnd, trimStart, truncate, unescape, uniqueId, upperCase, upperFirst, value, and words

参数:

  • value (*): 需要被包装为 lodash 实例的值。

返回值:

  • (Object): 返回 lodash 包装后的实例。

例子:

function square(n) {
  return n * n;
}

var wrapped = _([1, 2, 3]);

// Returns an unwrapped value.
wrapped.reduce(_.add);
// => 6

// Returns a wrapped value.
var squares = wrapped.map(square);

_.isArray(squares);
// => false

_.isArray(squares.value());
// => true
_.chain