Last active
August 29, 2015 14:07
-
-
Save RyoSugimoto/374eaa5147f24e163ec6 to your computer and use it in GitHub Desktop.
オブジェクトを結合する関数。
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 deepExtend (out) { | |
out = out || {}; | |
for (var i = 1; i < arguments.length; i++) { | |
var obj = arguments[i]; | |
if (!obj) { | |
continue; | |
} | |
for (var key in obj) { | |
if (obj.hasOwnProperty(key)) { | |
if (typeof obj[key] === 'object') { | |
deepExtend(out[key], obj[key]); | |
} else { | |
out[key] = obj[key]; | |
} | |
} | |
} | |
} | |
return out; | |
} | |
// Usage | |
deepExtend({}, objA, objB); |
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 (out) { | |
out = out || {}; | |
for (var i = 1; i < arguments.length; i++) { | |
if (!arguments[i]) { | |
continue; | |
} | |
for (var key in arguments[i]) { | |
if (arguments[i].hasOwnProperty(key)) { | |
out[key] = arguments[i][key]; | |
} | |
} | |
} | |
return out; | |
} | |
// Usage | |
extend({}, objA, objB); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment