Destructively map object properties function
问题 I was looking for an example or solution for mapping or changing values of an object 'destructively' instead of returning a new object or copy of the old object. underscore.js can be used since the project already uses this third party library. 回答1: This is how one such solution could look like, using underscore: function mapValuesDestructive (object, f) { _.each(object, function(value, key) { object[key] = f(value); }); } an example mapper function: function simpleAdder (value) { return