Skip to content

Instantly share code, notes, and snippets.

@lotsofcode
Last active August 29, 2015 14:20
Show Gist options
  • Save lotsofcode/b51521fddaa9e6cd9c62 to your computer and use it in GitHub Desktop.
Save lotsofcode/b51521fddaa9e6cd9c62 to your computer and use it in GitHub Desktop.
js extend
// ie9+
function extend (target, source) {
var a = Object.create(target);
Object.keys(source).map(function (prop) {
prop in a && (a[prop] = source[prop]);
});
return a;
};
// ltie9
var extend = function ( defaults, options ) {
var extended = {};
var prop;
for (prop in defaults) {
if (Object.prototype.hasOwnProperty.call(defaults, prop)) {
extended[prop] = defaults[prop];
}
}
for (prop in options) {
if (Object.prototype.hasOwnProperty.call(options, prop)) {
extended[prop] = options[prop];
}
}
return extended;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment