Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/JavaScript/copy.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ function deepClone(obj, hash = new WeakMap()) {
if (obj === null) return obj; // 如果是null或者undefined我就不进行拷贝操作
if (obj instanceof Date) return new Date(obj);
if (obj instanceof RegExp) return new RegExp(obj);
if (obj instanceof Set) return new Set(obj);
// 以上三个例子可以合并
// if (obj instanceof Date || obj instanceof RegExp || obj instanceof Set) {
// return new obj.constructor()
// }
// 可能是对象或者普通的值 如果是函数的话是不需要深拷贝
if (typeof obj !== "object") return obj;
// 是对象的话就要进行深拷贝
Expand Down