Skip to content

Instantly share code, notes, and snippets.

@monolithed
Created November 1, 2012 15:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save monolithed/3994364 to your computer and use it in GitHub Desktop.
Save monolithed/3994364 to your computer and use it in GitHub Desktop.
/* extend
*
* @param {object} from
* @param {object} to
* @param {Array} [ array ] - array of properties
*
* using:
* extend(object_1, object_2); // clone object
* extend(object_1, object_2, ['foo', 'bar']); // take some properties
*
*/
function extend(from, to, array)
{
if (Array.isArray(array)) {
var comment = null;
array.forEach(function(item, index) {
comment = item + '__comment';
if (from[comment])
to[comment] = from[comment];
to[item] = from[item];
});
}
else to = Object.create(from);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment