One lazy option:
_.extend(a, _.pick(b, _.keys(a)));
_.pick filters the source object using the .keys target, and the result is used to expand the target.
If you do not want to modify the original objects, just pass the empty object to the _.extend function.
_.extend({}, a, _.pick(b, _.keys(a)));
source share