Lodash从3到4的变化是什么,这段代码不能工作



我有一个这样的代码:

const _ = require('lodash');
const fn = _.partialRight(_.pick, _.identity);
const x = { some: 'value', empty: null };
const y = fn(x);
console.log('x:', x);
console.log('y:', y);

fn应该删除空属性

Result with Lodash 3.10.1:

x: { some: 'value', empty: null }
y: { some: 'value' }

Result with Lodash 4.15.0:

x: { some: 'value', empty: null }
y: {}

Lodash 4有什么变化,它不再工作了?

const fn = _.partialRight(_.pick, _.identity)更改为const fn = _.partialRight(_.pickBy, _.identity);

_.pick过去只是一个函数,但在最新的更新中,他们将其分解为_.pick_.pickBy。当你传递已知的键时,你会使用_.pick,当你使用自定义函数来测试是否应该根据你自己的参数选择键/值时,你会使用_.pickBy

https://lodash.com/docs/4.15.0挑选

https://lodash.com/docs/4.15.0 pickBy

从3.10.1更新到4.17.21

到目前为止我需要更新的函数是:

_contains to _.includes
_.pluck to _.map
_.findWhere to _.find
_.first to ._head
_.object to _.fromPairs

最新更新