Lodash 4.0.0 更新文档

发布时间:2019-08-19 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了Lodash 4.0.0 更新文档脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

Lodash 4.0.0 更新文档

v4.0.0

2016 年 1 月 12 日DiffDocs

兼容性警告
  • 专注于 npm,移除 Bower & component 包支持

  • 放弃IE 6-8 的支持

  • _.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]
  • 大多数方法移除 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 提案对齐

明显的变更

_.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

_.intersectionWith, _.join, _.pullAll, _.pullAllBy, _.reverse, _.sortedIndexBy, _.sortedIndexOf,
_.sortedLastIndexBy, _.sortedLastIndexOf, _.sortedUniq, _.sortedUniqBy, _.unionBy,
_.unionWith, _.uniqBy, _.uniqWith, _.xorBy, & _.xorWith

_.isLength, _.isMatchWith, _.isNil, _.isObjectLike, _.isSafeInteger, _.isSymbol, _.toInteger,
_.toLength, _.toNumber, _.toSafeInteger, & _.toString

_.omitBy, _.pickBy, _.setWith, _.toPairs, _.toPairsIn, & _.unset

    • 添加 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 的快速合并机制

      • 优化匹配方法,避免如果 objectsource 相同时进行深度爬行

      • 优化循环引用搜索

      • 优化 _.isEqual,避免当数组或对象拥有不同长度时的堆栈爬行

    • 支持 Emoji

      • Added support for astral symbols, combining diacritical marks, dingbats,
        regional indicator symbols, unicode modifiers, variation selectors, &

      zero-width-joiners to string methods

    • 功能性改进

    其他变更
    • _.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

    • 修正 _.floorprecision 参数时四舍五入的问题

    • 使 _(...) 成为一个迭代器 & 可迭代的对象

    • 使 _.drop, _.take, & 从右迭代的方法强制将 nundefined 转换为 0

    脚本宝典总结

    以上是脚本宝典为你收集整理的Lodash 4.0.0 更新文档全部内容,希望文章能够帮你解决Lodash 4.0.0 更新文档所遇到的问题。

    如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

    本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
    如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。