Skip to content

Instantly share code, notes, and snippets.

@heymichaelp
Last active August 29, 2015 14:01
Show Gist options
  • Save heymichaelp/e414bd177e749644b776 to your computer and use it in GitHub Desktop.
Save heymichaelp/e414bd177e749644b776 to your computer and use it in GitHub Desktop.
Underscore.js Mixin renameProp
_.mixin({
renameProp: function( obj, originalPropName, newPropName ) {
obj[ newPropName ] = obj[ originalPropName ];
delete obj[ originalPropName ];
return obj;
}
});
var person = {name: 'john', sex: 'm'};
_(person).renameProp('sex', 'gender'); // => {name: "bar", gender: "baz"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment