{"id":61855,"date":"2024-10-13T14:14:13","date_gmt":"2024-10-13T06:14:13","guid":{"rendered":"https:\/\/server.hk\/cnblog\/61855\/"},"modified":"2024-10-13T14:14:13","modified_gmt":"2024-10-13T06:14:13","slug":"javascript%e5%85%a7%e5%ad%98%e6%95%b8%e6%93%9a%e5%ba%ab%e6%8b%b7%e8%b2%9d%e6%8a%80%e5%b7%a7%e8%a9%b3%e8%a7%a3-js%e6%8b%b7%e8%b2%9d%e5%85%a7%e5%ad%98%e6%95%b8%e6%93%9a%e5%ba%ab","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/61855\/","title":{"rendered":"JavaScript\u5167\u5b58\u6578\u64da\u5eab\u62f7\u8c9d\u6280\u5de7\u8a73\u89e3 (js\u62f7\u8c9d\u5167\u5b58\u6578\u64da\u5eab)"},"content":{"rendered":"<h1 id=\"javascript%e5%85%a7%e5%ad%98%e6%95%b8%e6%93%9a%e5%ba%ab%e6%8b%b7%e8%b2%9d%e6%8a%80%e5%b7%a7%e8%a9%b3%e8%a7%a3-js%e6%8b%b7%e8%b2%9d%e5%85%a7%e5%ad%98%e6%95%b8%e6%93%9a%e5%ba%ab-qtwwylOyAr\">JavaScript\u5167\u5b58\u6578\u64da\u5eab\u62f7\u8c9d\u6280\u5de7\u8a73\u89e3 (js\u62f7\u8c9d\u5167\u5b58\u6578\u64da\u5eab)<\/h1>\n<p>\u5728\u73fe\u4ee3\u7684Web\u958b\u767c\u4e2d\uff0cJavaScript\u5df2\u7d93\u6210\u70ba\u4e00\u7a2e\u4e0d\u53ef\u6216\u7f3a\u7684\u8a9e\u8a00\u3002\u96a8\u8457\u61c9\u7528\u7a0b\u5e8f\u7684\u8907\u96dc\u6027\u589e\u52a0\uff0c\u958b\u767c\u8005\u9700\u8981\u6709\u6548\u5730\u7ba1\u7406\u6578\u64da\uff0c\u5c24\u5176\u662f\u5728\u5167\u5b58\u6578\u64da\u5eab\u7684\u4f7f\u7528\u4e0a\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0eJavaScript\u5167\u5b58\u6578\u64da\u5eab\u7684\u62f7\u8c9d\u6280\u5de7\uff0c\u5e6b\u52a9\u958b\u767c\u8005\u66f4\u597d\u5730\u7406\u89e3\u5982\u4f55\u5728\u5167\u5b58\u4e2d\u64cd\u4f5c\u6578\u64da\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af%e5%85%a7%e5%ad%98%e6%95%b8%e6%93%9a%e5%ba%ab%ef%bc%9f-qtwwylOyAr\">\u4ec0\u9ebc\u662f\u5167\u5b58\u6578\u64da\u5eab\uff1f<\/h2>\n<p>\u5167\u5b58\u6578\u64da\u5eab\u662f\u4e00\u7a2e\u5c07\u6578\u64da\u5b58\u5132\u5728\u5167\u5b58\u4e2d\u7684\u6578\u64da\u5eab\u7cfb\u7d71\uff0c\u9019\u4f7f\u5f97\u6578\u64da\u7684\u8b80\u53d6\u548c\u5beb\u5165\u901f\u5ea6\u975e\u5e38\u5feb\u3002\u8207\u50b3\u7d71\u7684\u78c1\u789f\u6578\u64da\u5eab\u76f8\u6bd4\uff0c\u5167\u5b58\u6578\u64da\u5eab\u5728\u6027\u80fd\u4e0a\u6709\u986f\u8457\u7684\u512a\u52e2\uff0c\u7279\u5225\u662f\u5728\u9700\u8981\u5feb\u901f\u97ff\u61c9\u7684\u61c9\u7528\u5834\u666f\u4e2d\uff0c\u5982\u5373\u6642\u5206\u6790\u548c\u9ad8\u983b\u4ea4\u6613\u3002<\/p>\n<h2 id=\"javascript%e4%b8%ad%e7%9a%84%e5%85%a7%e5%ad%98%e6%95%b8%e6%93%9a%e5%ba%ab-qtwwylOyAr\">JavaScript\u4e2d\u7684\u5167\u5b58\u6578\u64da\u5eab<\/h2>\n<p>\u5728JavaScript\u4e2d\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u4f7f\u7528\u5404\u7a2e\u5eab\u4f86\u5be6\u73fe\u5167\u5b58\u6578\u64da\u5eab\u7684\u529f\u80fd\uff0c\u4f8b\u5982 <code>Dexie.js<\/code> \u548c <code>LocalForage<\/code>\u3002\u9019\u4e9b\u5eab\u63d0\u4f9b\u4e86\u7c21\u55ae\u7684API\u4f86\u64cd\u4f5c\u6578\u64da\uff0c\u4e26\u4e14\u652f\u6301\u591a\u7a2e\u6578\u64da\u7d50\u69cb\uff0c\u5982\u5c0d\u8c61\u3001\u6578\u7d44\u7b49\u3002<\/p>\n<h2 id=\"%e6%8b%b7%e8%b2%9d%e5%85%a7%e5%ad%98%e6%95%b8%e6%93%9a%e5%ba%ab%e7%9a%84%e6%8a%80%e5%b7%a7-qtwwylOyAr\">\u62f7\u8c9d\u5167\u5b58\u6578\u64da\u5eab\u7684\u6280\u5de7<\/h2>\n<p>\u5728\u64cd\u4f5c\u5167\u5b58\u6578\u64da\u5eab\u6642\uff0c\u62f7\u8c9d\u6578\u64da\u662f\u4e00\u500b\u5e38\u898b\u7684\u9700\u6c42\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u6709\u6548\u7684\u62f7\u8c9d\u6280\u5de7\uff1a<\/p>\n<h3 id=\"1-%e4%bd%bf%e7%94%a8%e6%b7%ba%e6%8b%b7%e8%b2%9d-qtwwylOyAr\">1. \u4f7f\u7528\u6dfa\u62f7\u8c9d<\/h3>\n<p>\u6dfa\u62f7\u8c9d\u662f\u6307\u53ea\u62f7\u8c9d\u5c0d\u8c61\u7684\u7b2c\u4e00\u5c64\u5c6c\u6027\u3002\u53ef\u4ee5\u4f7f\u7528 <code>Object.assign()<\/code> \u6216\u5c55\u958b\u904b\u7b97\u7b26\uff08<code>...<\/code>\uff09\u4f86\u5be6\u73fe\u3002<\/p>\n<pre><code>const original = { a: 1, b: { c: 2 } };\nconst shallowCopy = Object.assign({}, original);\n\/\/ \u6216\u8005\u4f7f\u7528\u5c55\u958b\u904b\u7b97\u7b26\nconst shallowCopy2 = { ...original };\n<\/code><\/pre>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u6dfa\u62f7\u8c9d\u4e0d\u6703\u62f7\u8c9d\u5d4c\u5957\u5c0d\u8c61\u7684\u5c6c\u6027\uff0c\u9019\u53ef\u80fd\u6703\u5c0e\u81f4\u610f\u5916\u7684\u884c\u70ba\u3002<\/p>\n<h3 id=\"2-%e4%bd%bf%e7%94%a8%e6%b7%b1%e6%8b%b7%e8%b2%9d-qtwwylOyAr\">2. \u4f7f\u7528\u6df1\u62f7\u8c9d<\/h3>\n<p>\u6df1\u62f7\u8c9d\u5247\u6703\u62f7\u8c9d\u5c0d\u8c61\u7684\u6240\u6709\u5c64\u7d1a\u3002\u53ef\u4ee5\u4f7f\u7528 <code>JSON.parse()<\/code> \u548c <code>JSON.stringify()<\/code> \u4f86\u5be6\u73fe\u6df1\u62f7\u8c9d\uff0c\u4f46\u9019\u7a2e\u65b9\u6cd5\u6709\u4e00\u4e9b\u9650\u5236\uff0c\u4f8b\u5982\u7121\u6cd5\u62f7\u8c9d\u51fd\u6578\u548c\u7279\u6b8a\u5c0d\u8c61\uff08\u5982 <code>Date<\/code> \u548c <code>RegExp<\/code>\uff09\u3002<\/p>\n<pre><code>const original = { a: 1, b: { c: 2 } };\nconst deepCopy = JSON.parse(JSON.stringify(original));\n<\/code><\/pre>\n<h3 id=\"3-%e4%bd%bf%e7%94%a8%e7%ac%ac%e4%b8%89%e6%96%b9%e5%ba%ab-qtwwylOyAr\">3. \u4f7f\u7528\u7b2c\u4e09\u65b9\u5eab<\/h3>\n<p>\u5982\u679c\u9700\u8981\u66f4\u9ad8\u6548\u7684\u6df1\u62f7\u8c9d\uff0c\u53ef\u4ee5\u8003\u616e\u4f7f\u7528\u7b2c\u4e09\u65b9\u5eab\uff0c\u5982 <code>lodash<\/code> \u7684 <code>cloneDeep<\/code> \u65b9\u6cd5\u3002<\/p>\n<pre><code>const _ = require('lodash');\nconst original = { a: 1, b: { c: 2 } };\nconst deepCopy = _.cloneDeep(original);\n<\/code><\/pre>\n<h2 id=\"%e6%80%a7%e8%83%bd%e8%80%83%e9%87%8f-qtwwylOyAr\">\u6027\u80fd\u8003\u91cf<\/h2>\n<p>\u5728\u9078\u64c7\u62f7\u8c9d\u65b9\u6cd5\u6642\uff0c\u6027\u80fd\u662f\u4e00\u500b\u91cd\u8981\u7684\u8003\u91cf\u56e0\u7d20\u3002\u6dfa\u62f7\u8c9d\u901a\u5e38\u6bd4\u6df1\u62f7\u8c9d\u5feb\uff0c\u4f46\u5728\u67d0\u4e9b\u60c5\u6cc1\u4e0b\uff0c\u6df1\u62f7\u8c9d\u662f\u5fc5\u9808\u7684\u3002\u958b\u767c\u8005\u61c9\u6839\u64da\u5177\u9ad4\u9700\u6c42\u9078\u64c7\u5408\u9069\u7684\u65b9\u6cd5\u3002<\/p>\n<h2 id=\"%e7%b5%90%e8%ab%96-qtwwylOyAr\">\u7d50\u8ad6<\/h2>\n<p>JavaScript\u5167\u5b58\u6578\u64da\u5eab\u7684\u62f7\u8c9d\u6280\u5de7\u5c0d\u65bc\u958b\u767c\u8005\u4f86\u8aaa\u81f3\u95dc\u91cd\u8981\u3002\u7121\u8ad6\u662f\u6dfa\u62f7\u8c9d\u9084\u662f\u6df1\u62f7\u8c9d\uff0c\u9078\u64c7\u5408\u9069\u7684\u65b9\u6cd5\u53ef\u4ee5\u63d0\u9ad8\u61c9\u7528\u7a0b\u5e8f\u7684\u6027\u80fd\u548c\u53ef\u7dad\u8b77\u6027\u3002\u96a8\u8457\u6280\u8853\u7684\u767c\u5c55\uff0c\u638c\u63e1\u9019\u4e9b\u6280\u5de7\u5c07\u6709\u52a9\u65bc\u958b\u767c\u66f4\u9ad8\u6548\u7684Web\u61c9\u7528\u3002<\/p>\n<p>\u5982\u9700\u4e86\u89e3\u66f4\u591a\u6709\u95dc <a href=\"https:\/\/server.hk\">VPS<\/a> \u548c <a href=\"https:\/\/server.hk\">\u9999\u6e2f\u4f3a\u670d\u5668<\/a> \u7684\u8cc7\u8a0a\uff0c\u8acb\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22JavaScript\u5167\u5b58\u6578\u64da\u5eab\u7684\u62f7\u8c9d\u6280\u5de7\uff0c\u63d0\u5347\u6578\u64da\u8655\u7406\u6548\u7387\uff0c\u638c\u63e1\u6700\u4f73\u5be6\u8e10\uff0c\u512a\u5316\u6027\u80fd\u8207\u8cc7\u6e90\u7ba1\u7406\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-61855","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/61855","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=61855"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/61855\/revisions"}],"predecessor-version":[{"id":61856,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/61855\/revisions\/61856"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=61855"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=61855"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=61855"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}