Lodash 4.0.0 更新文档
来源:互联网 发布:google大数据 编辑:程序博客网 时间:2024/06/05 06:50
兼容性警告
- 专注于 npm,移除 Bower & Component 包支持
- 放弃对 IE 6-8 的支持
– Use es5-shim, & optionally es6-shim, to enable support
– 可以使用 es5-shim, & optionally es6-shim, 以继续开启支持 - 令 .forEach, .forIn, .forOwn, & .times 隐式结束链式调用队列
var wrapped = _([1, 2, 3]);// 在 3.10.1wrapped.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.0wrapped.forEach(function(n) { console.log(n); });// → logs each value from left to right and returns the array// → 从左到右记录每个值,并返回该数组
- 移除模块路径的分类名
// in 3.10.1var chunk = require('lodash/array/chunk');// in 4.0.0var 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]
- 大多数方法移除 thisArg
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 -第一个参数前面
低风险兼容性警告
- .debounce, .mixin, & _.throttle 移除布尔值 options 参数支持
- _.orderBy 移除布尔值 orders 参数的支持
- 令 .max, .min, & _.sum 只支持数组
- _.template 移除传统 options 参数签名
- 简化 _.escapeRegExp,以向已停止的 ES7 提案对齐
明显的变更
- 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
- 4 个 math 方法:
.maxBy, .mean, .minBy, & .sumBy
- 2 个 function 方法:
.flip & .unary
- 2 个 number 方法:
.clamp & .subtract
- 1 个 chain 方法:
_#next
- 1 个 collection 方法:
_.sampleSize
- 添加 3 别名
1. .extend 作为 .assignIn 的别名
2. .extendWith 作为 .assignInWith 的别名
3. .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
- Added support for astral symbols, combining diacritical marks, dingbats,
- 功能性改进
- 添加 .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 引用
- 确保 .add, .subtract, & _.sum 不会跳过 NaN 值
- 确保 .assign, .defaults, & _.merge 强制将 object 值转换为对象
- 确保使用 new 操作符调用时 _.bindKey 绑定的函数时调用 object[key]
- 确保 _.clone 能够将生成器视为函数
- 确保 _.clone 能够根据源对象的 [[Prototype]] 进行克隆
- 确保 _.defaults 能够根据 Object.prototype 分配属性
- 确保 _.defaultsDeep 不能将字符串并入数组
- 确保 .defaultsDeep & .merge 不会修改源对象
- 确保 _.defaultsDeep 能够循环引用
- 确保 _.isFunction 对生成器函数能够返回 true
- 确保 _.keys 在 Safari 9 的严格模式下将跳过 “length” 属性
- 确保 _.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文档
- Lodash 中文文档
- lodash "collection" methods lodash中文翻译更新中
- lodash "Array" methods中文 lodash中文 更新中
- lodash
- lodash
- lodash
- Lodash
- lodash
- lodash摘要
- 安装 lodash
- MXNet 1.0.0文档更新说明
- [更新] HSQLDB中文文档
- vc 单文档更新
- 每日更新文档
- 关于文档更新
- mongodb更新文档
- Git 常用操作(三) 作者及邮箱相关
- What Is Apache Spark
- Java常见面试题
- bash扩展功能总结
- 一些前端的强大工具
- Lodash 4.0.0 更新文档
- 一点一点解读紫书中例子--大整数类BigInteger (1)
- 人类生来真的平等吗?
- 项目总结-重写activity中的onNewIntent 方法
- 正则表达式——正则标记
- git撤销已Push到服务器的Commit
- 实现简单的 react-redux
- hive几种存储格式: Storage Format
- 什么是范数?