Skip to content

Instantly share code, notes, and snippets.

@rochnyak-d-i
Created October 28, 2014 04:51
Show Gist options
  • Save rochnyak-d-i/124a531486c12b8da238 to your computer and use it in GitHub Desktop.
Save rochnyak-d-i/124a531486c12b8da238 to your computer and use it in GitHub Desktop.
JS рекурсивное расширение
function extendDeep(parent, child) {
var
toStr = Object.prototype.toString
, astr = '[object Array]'
, i
;
child = child || {};
for(i in parent) {
if(parent.hasOwnProperty(i)) {
if(typeof parent[i] === "object") {
child[i] = (toStr.call(parent[i]) === astr) ? [] : {};
extendDeep(parent[i], child[i]);
} else {
child[i] = parent[i];
}
}
}
return child;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment