?
This document uses PHP Chinese website manual Release
創(chuàng)建一個(gè)lodash
包裝value
以啟用隱式方法鏈序列的對(duì)象。操作和返回?cái)?shù)組,集合和函數(shù)的方法可以鏈接在一起。檢索單個(gè)值或可能返回原始值的方法將自動(dòng)結(jié)束鏈序列并返回展開的值。否則,該值必須用解包_#value
。
明確的鏈序列,其必須用包裝除去 _#value
,可以使用被使能_.chain
。
鏈?zhǔn)椒椒ǖ膱?zhí)行是懶惰的,也就是說,它被推遲到_#value
隱式或顯式調(diào)用。
懶惰評(píng)估允許幾種方法來支持快捷融合。快捷融合是優(yōu)化合并迭代調(diào)用; 這可以避免創(chuàng)建中間數(shù)組,并且可以大大減少迭代執(zhí)行次數(shù)。如果該節(jié)應(yīng)用于數(shù)組并且迭代僅接受一個(gè)參數(shù),則鏈序列的節(jié)可以用于快捷融合。是否有資格進(jìn)行快捷方式融合的啟發(fā)式可能會(huì)發(fā)生變化。
只要_#value
方法直接或間接包含在構(gòu)建中,鏈接就支持在自定義構(gòu)建中。
除了lodash方法,包裝器Array
和String
方法。
包裝Array
方法是:
concat
, join
, pop
, push
, shift
, sort
, splice
, and unshift
包裝String
方法是:
replace
和split
支持快捷融合的封裝方法是:
at
, compact
, drop
, dropRight
, dropWhile
, filter
, find
, findLast
, head
, initial
, last
, map
, reject
, reverse
, slice
, tail
, take
, takeRight
, takeRightWhile
, takeWhile
, and toArray
The chainable wrapper methods are:
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
默認(rèn)情況下不可鏈接的包裝器方法是:
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
實(shí)例中的值。
(Object):返回新的lodash
包裝器實(shí)例。
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
創(chuàng)建一個(gè) lodash
封裝器實(shí)例,該實(shí)例包含value
啟用顯式方法鏈序列的封裝。這些序列的結(jié)果必須用包裝來解開_#value
。
1.3.0
value
(*):要包裝的值。
(Object):返回新的lodash
包裝器實(shí)例。
var users = [ { 'user': 'barney', 'age': 36 }, { 'user': 'fred', 'age': 40 }, { 'user': 'pebbles', 'age': 1 }]; var youngest = _ .chain(users) .sortBy('age') .map(function(o) { return o.user + ' is ' + o.age; }) .head() .value(); // => 'pebbles is 1'
此方法調(diào)用interceptor
并返回value
。攔截器被調(diào)用一個(gè)參數(shù); (價(jià)值)。這種方法的目的是“挖掘”一個(gè)方法鏈序列以修改中間結(jié)果。
0.1.0
value
(*):提供給的值interceptor
。
interceptor
(功能):調(diào)用的功能。
(*):返回value
。
_([1, 2, 3]) .tap(function(array) {// Mutate input array. array.pop(); }) .reverse() .value();// => [2, 1]
3.0.0
value
(*):提供給的值interceptor
。
interceptor
(功能):調(diào)用的功能。
(*):返回結(jié)果interceptor
。
_(' abc ') .chain() .trim() .thru(function(value) { return [value]; }) .value();// => ['abc']
使包裝可以迭代。
4.0.0
(Object):返回包裝器對(duì)象。
var wrapped = _([1, 2]); wrapped[Symbol.iterator]() === wrapped;// => true Array.from(wrapped);// => [1, 2]
1.0.0
[paths]
(...(string | string [])):要選擇的屬性路徑。
(Object):返回新的lodash
包裝器實(shí)例。
var object = { 'a': [{ 'b': { 'c': 3 } }, 4] }; _(object).at(['a[0].b.c', 'a[1]']).value();// => [3, 4]
lodash
使用顯式的方法鏈序列創(chuàng)建一個(gè)包裝器實(shí)例。
0.1.0
(Object):返回新的lodash
包裝器實(shí)例。
var users = [ { 'user': 'barney', 'age': 36 }, { 'user': 'fred', 'age': 40 }]; // A sequence without explicit chaining._(users).head(); // => { 'user': 'barney', 'age': 36 } // A sequence with explicit chaining._(users) .chain() .head() .pick('user') .value(); // => { 'user': 'barney' }
執(zhí)行鏈順序并返回包裝結(jié)果。
3.2.0
(Object):返回新的lodash
包裝器實(shí)例。
var array = [1, 2];var wrapped = _(array).push(3); console.log(array);// => [1, 2] wrapped = wrapped.commit();console.log(array);// => [1, 2, 3] wrapped.last();// => 3 console.log(array);// => [1, 2, 3]
4.0.0
(Object):返回下一個(gè)迭代器值。
var wrapped = _([1, 2]); wrapped.next();// => { 'done': false, 'value': 1 } wrapped.next();// => { 'done': false, 'value': 2 } wrapped.next();// => { 'done': true, 'value': undefined }
創(chuàng)建鏈序列種植的克隆value
作為包裝值。
3.2.0
value
(*):plant的取值。
(Object):返回新的lodash
包裝器實(shí)例。
function square(n) { return n * n;} var wrapped = _([1, 2]).map(square);var other = wrapped.plant([3, 4]); other.value();// => [9, 16] wrapped.value();// => [1, 4]
0.1.0
(Object):返回新的lodash
包裝器實(shí)例。
var array = [1, 2, 3]; _(array).reverse().value()// => [3, 2, 1] console.log(array);// => [3, 2, 1]
執(zhí)行鏈序列來解析展開的值。
0.1.0
_.prototype.toJSON, _.prototype.valueOf
(*):返回已解析的解包值。
_([1, 2, 3]).value();// => [1, 2, 3]