-
-
Save ericelliott/3660398 to your computer and use it in GitHub Desktop.
A simple and naive extend implementation
This file contains hidden or 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
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