Last active
August 29, 2015 14:20
-
-
Save lotsofcode/b51521fddaa9e6cd9c62 to your computer and use it in GitHub Desktop.
js extend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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