-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmixDeep.js
More file actions
32 lines (29 loc) · 858 Bytes
/
mixDeep.js
File metadata and controls
32 lines (29 loc) · 858 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/* UMD.define */ (typeof define=="function"&&define||function(d,f,m){m={module:module,require:require};module.exports=f.apply(null,d.map(function(n){return m[n]||require(n)}))})
([], function(){
"use strict";
//TODO: consider defineProperty() & Co. on capable JS engines.
function identity(x){ return x; }
return function mixDeep(t, s, dontCreate, cloneFn){
cloneFn = cloneFn || identity;
main: {
if(!s || typeof s != "object" || s instanceof Date || s instanceof RegExp){
return cloneFn(s);
}
if(s instanceof Array){
if(!(t instanceof Array)){
return cloneFn(s);
}
}
// copy members
for(var k in s){
if(k in t){
t[k] = mixDeep(t[k], s[k], dontCreate, cloneFn);
}else if(!dontCreate){
t[k] = cloneFn(s[k]);
}
}
return t;
}
throw new Error("mixDeep: Structural mismatch");
};
});