Skip to content

Instantly share code, notes, and snippets.

@flesch
Created July 3, 2012 15:12
Show Gist options
  • Save flesch/3040349 to your computer and use it in GitHub Desktop.
Save flesch/3040349 to your computer and use it in GitHub Desktop.
Shallow Copy of an Object
function extend(a, b) {
var c = {}, attr;
for (attr in a) {
if (Object.prototype.hasOwnProperty.call(a, attr)) {
c[attr] = a[attr];
}
}
for (attr in b) {
if (Object.prototype.hasOwnProperty.call(b, attr)) {
c[attr] = b[attr];
}
}
return c;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment