s
Showing
2 changed files
with
3 additions
and
26 deletions
... | @@ -51,30 +51,4 @@ export default { | ... | @@ -51,30 +51,4 @@ export default { |
51 | } | 51 | } |
52 | return newArr; | 52 | return newArr; |
53 | }, | 53 | }, |
54 | /** | ||
55 | * @brief:深度拷贝 | ||
56 | * @param {*} data => obj | ||
57 | * */ | ||
58 | deepClone: function (data) { | ||
59 | var type = this.getType(data); | ||
60 | var obj; | ||
61 | if (type === 'array') { | ||
62 | obj = []; | ||
63 | } else if (type === 'object') { | ||
64 | obj = {}; | ||
65 | } else { | ||
66 | //不再具有下一层次 | ||
67 | return data; | ||
68 | } | ||
69 | if (type === 'array') { | ||
70 | for (var i = 0, len = data.length; i < len; i++) { | ||
71 | obj.push(this.deepClone(data[i])); | ||
72 | } | ||
73 | } else if (type === 'object') { | ||
74 | for (var key in data) { | ||
75 | obj[key] = this.deepClone(data[key]); | ||
76 | } | ||
77 | } | ||
78 | return obj; | ||
79 | }, | ||
80 | } | 54 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or sign in to post a comment