W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
創(chuàng)建一個lodash對象,包裝value后的對象啟用隱式方法鏈。返回的數(shù)組、集合、方法相互之間能夠鏈?zhǔn)秸{(diào)用。檢索唯一值或返回原始值會自動解除鏈條并返回計算后的值,否則需要調(diào)用 _#value 方法解除鏈(即獲得計算結(jié)果)。顯式鏈?zhǔn)秸{(diào)用,在任何情況下需要先用 _#value 解除鏈后,才能使用_.chain 開啟。鏈?zhǔn)椒椒ㄊ嵌栊杂嬎愕?,直到隱式或者顯式調(diào)用了 _#value 才會執(zhí)行計算。惰性計算接受幾種支持 shortcut fusion 的方法, shortcut fusion 是一種通過合并鏈?zhǔn)?iteratee 調(diào)用從而大大降低迭代的次數(shù)以提高執(zhí)行性能的方式。 部分鏈有資格 shortcut fusion,如果它至少有超過200個元素的數(shù)組和任何只接受一個參數(shù)的 iteratees。 觸發(fā)的方式是任何一個 shortcut fusion 有了變化。鏈?zhǔn)椒椒ㄖС侄ㄖ瓢姹荆灰?nbsp;_#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
支持 鏈?zhǔn)秸{(diào)用 的方法:
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
默認 不 支持 鏈?zhǔn)秸{(diào)用 的方法:
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
(Object): 返回 lodash 包裝后的實例。
function square(n) { return n * n;}
var wrapped = _([1, 2, 3]);
// 返回未包裝的值
wrapped.reduce(_.add);
// => 6 // 返回鏈?zhǔn)桨b的值
var squares = wrapped.map(square);
_.isArray(squares);
// => false
_.isArray(squares.value());
// => true
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: