fix: get copy.

This commit is contained in:
Ansolve 2024-01-15 14:27:59 +08:00
parent 514751d371
commit 2190dfe083
No known key found for this signature in database
GPG Key ID: 2F2873AC9538CC2D
1 changed files with 11 additions and 4 deletions

View File

@ -814,6 +814,7 @@ export class Get extends Uninstantable {
"[object Object]": true,
"[object Array]": true,
"[object Arguments]": true,
"[object Date]": true
};
if (typeof obj !== "object" || obj === null || !canTranverse[getType(obj)])
@ -827,16 +828,22 @@ export class Get extends Uninstantable {
const target =
constructor
? (
// 这类数据处理单独处理
// 这类数据处理单独处理
// 实际上需要处理的只有Map和Set
// 除此之外的就只能祝愿有拷贝构造函数了
(Array.isArray(obj) || obj instanceof Map || obj instanceof Set)
(Array.isArray(obj) || obj instanceof Map || obj instanceof Set || constructor === Object)
// @ts-ignore
? new constructor()
// @ts-ignore
: new constructor(obj)
: (
(constructor.name in window && /\[native code\]/.test(constructor.toString()))
// @ts-ignore
? new constructor(obj)
: obj
)
)
: Object.create(null);
if (target === obj) return target;
map.set(obj, target);
if (obj instanceof Map) {