问题
I have a code like this:
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 is supposed to remove empty properties
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: {}
What has changed in Lodash 4 that it's not working anymore?
回答1:
change your const fn = _.partialRight(_.pick, _.identity) to
const fn = _.partialRight(_.pickBy, _.identity);
_.pick used to be just one function but they broke it out into _.pick and _.pickBy in the latest updates. you would use _.pick when you are passing in known keys and _.pickBy when you are using a custom function to test if a key/value should be picked based on your own parameters,
https://lodash.com/docs/4.15.0#pick
https://lodash.com/docs/4.15.0#pickBy
来源:https://stackoverflow.com/questions/39503069/what-has-changed-in-lodash-from-3-to-4-that-this-code-is-not-working