Last change
on this file since fa375fe was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
605 bytes
|
Line | |
---|
1 | export function klona(val) {
|
---|
2 | var k, out, tmp;
|
---|
3 |
|
---|
4 | if (Array.isArray(val)) {
|
---|
5 | out = Array(k=val.length);
|
---|
6 | while (k--) out[k] = (tmp=val[k]) && typeof tmp === 'object' ? klona(tmp) : tmp;
|
---|
7 | return out;
|
---|
8 | }
|
---|
9 |
|
---|
10 | if (Object.prototype.toString.call(val) === '[object Object]') {
|
---|
11 | out = {}; // null
|
---|
12 | for (k in val) {
|
---|
13 | if (k === '__proto__') {
|
---|
14 | Object.defineProperty(out, k, {
|
---|
15 | value: klona(val[k]),
|
---|
16 | configurable: true,
|
---|
17 | enumerable: true,
|
---|
18 | writable: true,
|
---|
19 | });
|
---|
20 | } else {
|
---|
21 | out[k] = (tmp=val[k]) && typeof tmp === 'object' ? klona(tmp) : tmp;
|
---|
22 | }
|
---|
23 | }
|
---|
24 | return out;
|
---|
25 | }
|
---|
26 |
|
---|
27 | return val;
|
---|
28 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.