Created
October 28, 2014 04:51
-
-
Save rochnyak-d-i/124a531486c12b8da238 to your computer and use it in GitHub Desktop.
JS рекурсивное расширение
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 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