Last active
August 29, 2015 14:27
-
-
Save daniellizik/b7cc6d055877d13367a5 to your computer and use it in GitHub Desktop.
extend function, merges object properties into first passed
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
function extend() { | |
var args = Array.prototype.slice.call(arguments); | |
var base = args.slice(0, 1)[0]; | |
var objs = args.slice(1); | |
for (var i = 0; i < objs.length; i++) { | |
for (var p in objs[i]) { | |
if (!base[p]) base[p] = objs[i][p]; | |
} | |
} | |
return base; | |
} | |
/** | |
* var extended = extend({}, { a: "a" }, { b: "b" }); | |
* --> { a: "a", b: "b" } | |
* | |
* var extended = extend({ a: "a" }, { d: "d", e: "e" }, { d: "d" } ); | |
* --> { a: "a", d: "d", e: "e" } | |
* / |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment