Skip to content

Instantly share code, notes, and snippets.

@ericelliott
Forked from gkatsev/extend.js
Created September 6, 2012 21:10
Show Gist options
  • Save ericelliott/3660398 to your computer and use it in GitHub Desktop.
Save ericelliott/3660398 to your computer and use it in GitHub Desktop.
A simple and naive extend implementation
function extend(obj) {
var args = [].slice.call(arguments, 1);
args.forEach(function (source) {
var prop;
for (prop in source) {
if (source.hasOwnProperty(prop)) {
obj[prop] = source[prop];
}
}
});
return obj;
}
var obj = {
a : 1
, b : 2
, c : 3
}
var ext = {
a : 4
, b : 5
}
extend(obj, ext)
// { a: 4, b: 5, c: 3 }
obj = extend(obj, ext)
// { a: 4, b: 5, c: 3 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment