Lodash 4.0.0 更新文档

兼容性警告
  • 专注于 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 提案对齐

明显的变更
  • 4 kB (gzipped)core build (65 个方法; Backbone v1.2.4compatible)_.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

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


  • _.detect,_.foldl,_.foldr,_.include,_.inject,_.methods,_.object,_.#run,_.select, & _.unique

    • 性能优化

      • 开启_.at,_.find&_.findLast的快速合并机制

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

      • 优化循环引用搜索

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

    • 支持 Emoji

      zero-width-joiners to string methods

      • Added support for astral symbols,

      • combining diacritical marks, dingbats, regional indicator symbols, unicode modifiers, variation selectors, &

    • 功能性改进

    其他变更
    • _.memoize.Cache添加clear方法

    • 为防反跳函数和节流阀函数添加flush方法

    • _.clone,_.isEqual, & _.toArray 支持 ES6 映射、集合 & 标记

    • _.isEqual支持数组缓存

    • _.toArray支持转换迭代器

    • _.zipObject支持深度路径

    • Changed UMD to export to windoworself 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的克隆队列充值迭代器的数据

    • 确保_.randommin大于max时交换min&max

    • 确保_.range preserves the sign of startof-0

    • 确保_.reduce&_.reduceRight在数组分支中使用getIteratee

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

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

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