From 15b2b423b262e1e372575c107cd79339e8dfc325 Mon Sep 17 00:00:00 2001 From: yeyuqiudeng Date: Sun, 19 Apr 2020 23:31:02 +0800 Subject: [PATCH] =?UTF-8?q?update:=20=E5=AE=8C=E6=88=90cloneDeep?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + SUMMARY.md | 1 + cloneDeep.md | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 cloneDeep.md diff --git a/README.md b/README.md index f88badb..46165e9 100644 --- a/README.md +++ b/README.md @@ -223,6 +223,7 @@ * [castArray](castArray.md) * [keysIn](keysIn.md) * [clone](clone.md) +* [cloneDeep](cloneDeep.md) ## License diff --git a/SUMMARY.md b/SUMMARY.md index d84f6a2..b874178 100644 --- a/SUMMARY.md +++ b/SUMMARY.md @@ -202,4 +202,5 @@ + [castArray](castArray.md) + [keysIn](keysIn.md) + [clone](clone.md) ++ [cloneDeep](cloneDeep.md) diff --git a/cloneDeep.md b/cloneDeep.md new file mode 100644 index 0000000..aba6e82 --- /dev/null +++ b/cloneDeep.md @@ -0,0 +1,36 @@ +# lodash源码分析之cloneDeep + +本文为读 lodash 源码的第二百篇,后续文章会更新到这个仓库中,欢迎 star:[pocket-lodash](https://github.com/yeyuqiudeng/pocket-lodash) + +gitbook也会同步仓库的更新,gitbook地址:[pocket-lodash](https://www.gitbook.com/book/yeyuqiudeng/pocket-lodash/details) + +## 依赖 + +```javascript +import baseClone from './.internal/baseClone.js' +``` + +[《lodash源码分析之baseClone》](internal/baseClone.md) + + +## 源码分析 + +`cloneDeep` 会对传入的 `value` 做深度复制,源码如下: + +```javascript +const CLONE_DEEP_FLAG = 1 +const CLONE_SYMBOLS_FLAG = 4 +function cloneDeep(value) { + return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG) +} +``` + +和 `clone` 一样,也是调用 `baseClone` 来实现,只不过 `bitmask` 传入的是 `CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG` ,也即开启深度复制和复制 `Symbol` 属性。 + +## License + +[署名-非商业性使用-禁止演绎 4.0 国际 (CC BY-NC-ND 4.0)](http://creativecommons.org/licenses/by-nc-nd/4.0/) + +最后,所有文章都会同步发送到微信公众号上,欢迎关注,欢迎提意见: ![](https://raw.githubusercontent.com/yeyuqiudeng/resource/master/images/qrcode_front-end-article.jpg) + +作者:对角另一面 \ No newline at end of file