Last active
January 18, 2016 16:38
-
-
Save basarat/43b841abc6cfe6db1271 to your computer and use it in GitHub Desktop.
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
export function extend(...args: any[]):any { | |
var extendRecursive = (x:any[], extractFields:(y)=>void) => { | |
for (let obj of x) { | |
if (obj) { | |
if (obj instanceof Array) { | |
extendRecursive(obj, extractFields) | |
} | |
else { | |
extractFields(obj); | |
} | |
} | |
} | |
} | |
let newObj = {}; | |
extendRecursive(args, obj => { | |
for (let key in obj) { | |
//copy all the fields | |
newObj[key] = obj[key]; | |
} | |
}); | |
return newObj; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment