脚本宝典收集整理的这篇文章主要介绍了Lodash 4.0.0 更新文档,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
Lodash 4.0.0 更新文档
v4.0.0
2016 年 1 月 12 日 — Diff — Docs
兼容性警告
-
-
令 _.foreach
, _.forIn
, _.forOwn
, & _.times
隐式结束链式调用队列
VAR wrapPEd = _([1, 2, 3]);
// 在 3.10.1
wrapped.forEach(function(n) { console.LOG(n); });
// → returns the lodash wrapper wIThout logging until `value` is called
// → 在 `value` 调用之前返回 lodash 包装器(并不会打印记录)
wrapped.forEach(function(n) { console.log(n); }).value();
// → logs each value From left to right and returns the array
// → 从左到右记录每个值,并返回该数组
// 在 4.0.0
wrapped.forEach(function(n) { console.log(n); });
// → logs each value from left to right and returns the array
// → 从左到右记录每个值,并返回该数组
-
移除模块路径的分类名
// in 3.10.1
var chunk = require('lodash/array/chunk');
// in 4.0.0
var chunk = require('lodash/chunk');
-
移除 _.pluck
,使用 _.map
迭代器简写代替
var objects = [{ 'a': 1 }, { 'a': 2 }];
// in 3.10.1
_.pluck(objects, 'a'); // → [1, 2]
_.map(objects, 'a'); // → [1, 2]
// in 4.0.0
_.map(objects, 'a'); // → [1, 2]
-
var objects = [{ 'a': 1 }, { 'a': 2 }];
var context = { 'b': 5 };
function callback(item) {
return item.a + this.b;
}
// in 3.10.1
_.map(objects, callback, context);
// in 4.0.0
_.map(objects, _.bind(callback, context));
-
将 _.max
& _.min
拆分成 _.maxBy & _.minBy
var array = [1, 2, 3],
objects = [{ 'a': 1 }, { 'a': 2 }];
// in 3.10.1
_.max(array); // → 3
_.max(objects, 'a'); // → { 'a': 2 }
_.min(array); // → 1
_.min(objects, 'a'); // → { 'a': 1 }
// in 4.0.0
_.max(array); // → 3
_.maxBy(objects, 'a'); // → { 'a': 2 }
_.min(array); // → 1
_.minBy(objects, 'a'); // → { 'a': 1 }
-
移除方法
移除 _.support
移除 _.findWhere
,使用 _.find
迭代器简写代替
移除 _.where
,使用 _.filter
迭代器简写代替
移除 _.pluck
,使用 _map
迭代器简写代替
-
方法名变更
_.First
更名为 _.head
_.indexBy
更名为 _.keyBy
_.invoke
更名为 _.invokeMap
_.modArgs
更名为 _.overArgs
_.padLeft
& _.padRight
更名为 _padStart
& _.padEnd
_.pairs
更名为 _.toPairs
_.rest
更名为 _.tail
_.restParam
更名为 _.rest
_.sortByOrder
更名为 _.orderBy
_.triMLeft
& _.trimRight
更名为 _.trimStart
& _.trimEnd
_.trunc
更名为 _.truncate
-
拆分方法
从 _.indexOf
& _.lastIndexOf
拆分出 _.sortedIndexOf
& _.sortedLastIndexOf
从_.max
& _.min
拆分出 _.maxBy
& _.minBy
从 _.omit
& _.pick
拆分出 _.omitBy
& _.pickBy
从 _.sample
拆分出 _.sampleSize
从 _.sortedIndex
拆分出 _.sortedIndexBy
从_.sortedLastIndex
拆分出 _.sortedLastIndexBy
从 _.uniq
拆分出 _.sortedUniq
, _.sortedUniqBy
, & _.uniqBy
将 _.sortByAll
并入 _.sortBy
变更 _.at
的类别为 “Object”
变更 _.bindAll
的类别为 Utility
令 "By" 方法的迭代器只提供一个参数
令 _.capitalize
会转换第一个字符为大写 & 其他字符为小写
令 _.functions
返回自有方法的方法名名
令 _.words
默认可链式调用
_.clone
& _.flatten
移除 isDeep
参数
当未指定方法名时,移除_.bindAll
绑定所有方法的支持
_.before
& _.after
移除 func
-第一个参数前面
低风险兼容性警告
_.orderBy
移除布尔值 orders
参数的支持
令 _.max
, _.min
, & _.sum
只支持数组
_.template
移除传统 options
参数签名
明显的变更
4 kB (gzipped) core build (65 个方法; Backbone v1.2.4 compatible)
_.assignIn
, _.before
, _.bind
, _.chain
, _.clone
, _.COMpact
, _.concat
,
_.create
, _.defaults
, _.defer
, _.delay
, _.each
, _.escape
, _.every
,
_.filter
, _.find
, _.first
, _.flatten
, _.flattenDeep
, _.forEach
,
_.has
, _.head
, _.identity
, _.indexOf
, _.invokeMap
, _.isarguments
,
_.isArray
, _.isBoolean
, _.isDate
, _.iSEMpty
, _.isEqual
, _.isFinite
,
_.isFunction
, _.isNaN
, _.isNull
, _.isNumber
, _.isObject
, _.isRegExp
,
_.isString
, _.isUndefined
, _.iteratee
, _.keys
, _.last
, _.map
,
_.max
, _.min
, _.mixin
, _.negate
, _.noConflict
, _.noop
, _.now
,
_.once
, _.pick
, _.reduce
, _.result
, _.size
, _.slice
, _.some
,
_.sortBy
, _.tap
, _.thru
, _.toArray
, _.uniqueId
, _.value
, & _.values
-
新增 80 个方法
23 个 array 方法:
_.concat, _.differenceBy, _.differenceWith, _.flatMap, _.fromPairs, _.intersectionBy,
_.intersectionWith, _.join, _.pullAll, _.pullAllBy, _.reverse, _.sortedIndexBy, _.sortedIndexOf,
_.sortedLastIndexBy, _.sortedLastIndexOf, _.sortedUniq, _.sortedUniqBy, _.unionBy,
_.unionWith, _.uniqBy, _.uniqWith, _.xorBy, & _.xorWith
18 个 lang 方法:
_.cloneDeepWith, _.cloneWith, _.eq, _.isArrayLike, _.isArrayLikeObject, _.isEqualWith, _.isInteger,
_.isLength, _.isMatchWith, _.isNil, _.isObjectLike, _.isSafeInteger, _.isSymbol, _.toInteger,
_.toLength, _.toNumber, _.toSafeInteger, & _.toString
13 个object :
_.assignIn, _.assignInWith, _.assignWith, _.functionsIn, _.hasIn, _.invoke, _.mergeWith,
_.omitBy, _.pickBy, _.setWith, _.toPairs, _.toPairsIn, & _.unset
8 个 string 方法:
_.lowerCase, _.lowerFirst, _.replace, _.split, _.upperCase, _.upperFirst, _.toLower, & _.toUpper
8 个 utility 方法:
_.cond, _.conforms, _.nthArg, _.over, _.overEvery, _.overSome, _.rangeRight, & _.toPath
2 个 number 方法:
_.clamp & _.subtract
1 个 chain 方法:
_#next
1 个 collection 方法:
_.sampleSize
-
添加 3 别名
_.extend
作为 _.assignIn
的别名
_.extendWith
作为 _.assignInWith
的别名
_.first
作为 _.head
的别名
移除 17 个别名
_.all
, _.any
, _.backflow
, _.callback
, _.collect
, _.compose
, _.contains
,
_.detect
, _.foldl
, _.foldr
, _.include
, _.inject
, _.methods
, _.object
,
_.#run
, _.select
, & _.unique
-
性能优化
开启 _.at
, _.find
& _.findLast
的快速合并机制
优化匹配方法,避免如果 object
和 source
相同时进行深度爬行
优化循环引用搜索
优化 _.isEqual
,避免当数组或对象拥有不同长度时的堆栈爬行
-
支持 Emoji
Added support for astral symbols, combining diacritical marks, dingbats,
regional indicator symbols, unicode modifiers, variation selectors, &
zero-width-joiners to string methods
-
功能性改进
添加 _.cond, _.conforms, _.flip, _.nthArg, _.over, _.overEvery, _.overSome, & _.unary
将 lodash-fp
移动到 lodash
,使用 require('lodash/fp')
作为不可变 iteratee-first data-last 方法
其他变更
为 _.memoize.Cache
添加 clear
方法
为防反跳函数和节流阀函数添加 flush
方法
_.clone
, _.isEqual
, & _.toArray
支持 ES6 映射、集合 & 标记
_.isEqual
支持数组缓存
_.toArray
支持转换迭代器
_.zIPObject
支持深度路径
Changed UMD to export to window
or self
when available regardless of other exports
_.flow
& _.flowRight
现在可以接受一个函数数组
确保 “Collection” 方法能将函数视为对象
确保防反跳方法 cancel
能够清除 args
& thisArg
引用
确保 _.assign
, _.defaults
, & _.merge
强制将 object
值转换为对象
确保 _.clone
能够将生成器视为函数
确保 _.defaultsDeep
不能将字符串并入数组
确保 _.defaultsDeep
& _.merge
不会修改源对象
确保 _.defaultsDeep
能够循环引用
确保 _.isFunction
对生成器函数能够返回 true
确保 _.merge
能够直接布置类型数组
确保 _.merge
不能将字符串转换为数组
确保 _.merge
能够将纯粹对象合并到非纯粹对象中
确保 _#plant
的克隆队列充值迭代器的数据
确保 _.random
min
大于 max
时交换 min
& max
确保 _.range
preserves the sign of start
of -0
确保 _.reduce
& _.reduceRight
在数组分支中使用 getIteratee
修正 _.floor
带 precision
参数时四舍五入的问题
使 _(...)
成为一个迭代器 & 可迭代的对象
使 _.drop
, _.take
, & 从右迭代的方法强制将 n
由 undefined
转换为 0
以上是脚本宝典为你收集整理的Lodash 4.0.0 更新文档全部内容,希望文章能够帮你解决Lodash 4.0.0 更新文档所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。