You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
621 B
30 lines
621 B
2 years ago
|
function klona(val) {
|
||
|
var k, out, tmp;
|
||
|
|
||
|
if (Array.isArray(val)) {
|
||
|
out = Array(k=val.length);
|
||
|
while (k--) out[k] = (tmp=val[k]) && typeof tmp === 'object' ? klona(tmp) : tmp;
|
||
|
return out;
|
||
|
}
|
||
|
|
||
|
if (Object.prototype.toString.call(val) === '[object Object]') {
|
||
|
out = {}; // null
|
||
|
for (k in val) {
|
||
|
if (k === '__proto__') {
|
||
|
Object.defineProperty(out, k, {
|
||
|
value: klona(val[k]),
|
||
|
configurable: true,
|
||
|
enumerable: true,
|
||
|
writable: true,
|
||
|
});
|
||
|
} else {
|
||
|
out[k] = (tmp=val[k]) && typeof tmp === 'object' ? klona(tmp) : tmp;
|
||
|
}
|
||
|
}
|
||
|
return out;
|
||
|
}
|
||
|
|
||
|
return val;
|
||
|
}
|
||
|
|
||
|
exports.klona = klona;
|