{"id":3181,"date":"2024-11-10T17:42:41","date_gmt":"2024-11-10T09:42:41","guid":{"rendered":"https:\/\/fwq.ai\/blog\/3181\/"},"modified":"2024-11-10T17:42:41","modified_gmt":"2024-11-10T09:42:41","slug":"js%e5%a6%82%e4%bd%95%e4%bc%a0%e9%80%92%e5%af%b9%e8%b1%a1","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/3181\/","title":{"rendered":"js\u5982\u4f55\u4f20\u9012\u5bf9\u8c61"},"content":{"rendered":"<blockquote><p>\n  \u53ef\u4ee5\u4f7f\u7528 javascript \u4f20\u9012\u5bf9\u8c61\u7684\u65b9\u5f0f\u6709\uff1a\u5f15\u7528\u4f20\u9012\u4e00\u4e2a\u5bf9\u8c61\u7684\u526f\u672c\uff0c\u503c\u4f20\u9012\u521b\u5efa\u65b0\u5bf9\u8c61\u5e76\u590d\u5236\u5c5e\u6027\u503c\uff0c\u7ed3\u6784\u5316\u514b\u9686\u7b97\u6cd5\u521b\u5efa\u5b8c\u5168\u72ec\u7acb\u7684\u514b\u9686\u3002\u9009\u62e9\u65b9\u5f0f\u53d6\u51b3\u4e8e\u6240\u9700\u7684\u8bed\u4e49\uff0c\u9700\u8981\u4fee\u6539\u539f\u59cb\u5bf9\u8c61\u65f6\u4f7f\u7528\u5f15\u7528\u4f20\u9012\uff0c\u9700\u8981\u72ec\u7acb\u526f\u672c\u65f6\u4f7f\u7528\u503c\u4f20\u9012\u6216\u7ed3\u6784\u5316\u514b\u9686\u7b97\u6cd5\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/08\/2024110806242526932.jpg\" class=\"aligncenter\" title=\"js\u5982\u4f55\u4f20\u9012\u5bf9\u8c61\u63d2\u56fe\" alt=\"js\u5982\u4f55\u4f20\u9012\u5bf9\u8c61\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528 JavaScript \u4f20\u9012\u5bf9\u8c61<\/strong><\/p>\n<p>JavaScript \u4e2d\u4f20\u9012\u5bf9\u8c61\u7684\u65b9\u5f0f\u6709\u4ee5\u4e0b\u51e0\u79cd\uff1a<\/p>\n<p><strong>1. \u5f15\u7528\u4f20\u9012\uff08\u4f20\u9012\u5bf9\u8c61\u7684\u5f15\u7528\uff09<\/strong><\/p>\n<ul>\n<li>\u521b\u5efa\u4e00\u4e2a\u5bf9\u8c61\u7684\u526f\u672c\uff0c\u7136\u540e\u4f20\u9012\u526f\u672c\u3002<\/li>\n<li>\u4efb\u4f55\u5bf9\u526f\u672c\u7684\u66f4\u6539\u90fd\u4f1a\u5f71\u54cd\u539f\u59cb\u5bf9\u8c61\u3002<\/li>\n<\/ul>\n<pre>\/\/ \u521b\u5efa\u4e00\u4e2a\u5bf9\u8c61\nconst obj = { name: \"John\", age: 30 };\n\n\/\/ \u4f20\u9012\u526f\u672c\nconst newObj = obj;\n\n\/\/ \u4fee\u6539\u526f\u672c\nnewObj.age = 31;\n\n\/\/ \u539f\u59cb\u5bf9\u8c61\u4e5f\u88ab\u4fee\u6539\nconsole.log(obj.age); \/\/ \u8f93\u51fa\uff1a31<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>2. \u503c\u4f20\u9012\uff08\u4f20\u9012\u5bf9\u8c61\u7684\u5c5e\u6027\u503c\uff09<\/strong><\/p>\n<ul>\n<li>\u521b\u5efa\u4e00\u4e2a\u65b0\u5bf9\u8c61\uff0c\u7136\u540e\u5c06\u539f\u59cb\u5bf9\u8c61\u7684\u5c5e\u6027\u503c\u590d\u5236\u5230\u65b0\u5bf9\u8c61\u4e2d\u3002<\/li>\n<li>\u4efb\u4f55\u5bf9\u65b0\u5bf9\u8c61\u7684\u66f4\u6539\u90fd\u4e0d\u4f1a\u5f71\u54cd\u539f\u59cb\u5bf9\u8c61\u3002<\/li>\n<\/ul>\n<pre>\/\/ \u521b\u5efa\u4e00\u4e2a\u5bf9\u8c61\nconst obj = { name: \"John\", age: 30 };\n\n\/\/ \u4f20\u9012\u503c\nconst newObj = Object.assign({}, obj);\n\n\/\/ \u4fee\u6539\u65b0\u5bf9\u8c61\nnewObj.age = 31;\n\n\/\/ \u539f\u59cb\u5bf9\u8c61\u4e0d\u53d7\u5f71\u54cd\nconsole.log(obj.age); \/\/ \u8f93\u51fa\uff1a30<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>3. \u7ed3\u6784\u5316\u514b\u9686\u7b97\u6cd5<\/strong><\/p>\n<ul>\n<li>\u4f7f\u7528 structuredClone() \u65b9\u6cd5\u521b\u5efa\u539f\u59cb\u5bf9\u8c61\u7684\u6df1\u5ea6\u514b\u9686\u3002<\/li>\n<li>\u526f\u672c\u4e0e\u539f\u59cb\u5bf9\u8c61\u5b8c\u5168\u72ec\u7acb\uff0c\u4efb\u4f55\u66f4\u6539\u90fd\u4e0d\u4f1a\u5f71\u54cd\u5f7c\u6b64\u3002<\/li>\n<\/ul>\n<pre>\/\/ \u521b\u5efa\u4e00\u4e2a\u5bf9\u8c61\nconst obj = { name: \"John\", age: 30 };\n\n\/\/ \u4f20\u9012\u514b\u9686\nconst newObj = structuredClone(obj);\n\n\/\/ \u4fee\u6539\u514b\u9686\nnewObj.age = 31;\n\n\/\/ \u539f\u59cb\u5bf9\u8c61\u4e0d\u53d7\u5f71\u54cd\nconsole.log(obj.age); \/\/ \u8f93\u51fa\uff1a30<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u9009\u62e9\u5408\u9002\u7684\u4f20\u9012\u65b9\u5f0f<\/strong><\/p>\n<p>\u9009\u62e9\u54ea\u79cd\u4f20\u9012\u65b9\u5f0f\u53d6\u51b3\u4e8e\u6240\u9700\u7684\u8bed\u4e49\uff1a<\/p>\n<ul>\n<li>\u5982\u679c\u9700\u8981\u5bf9\u539f\u59cb\u5bf9\u8c61\u8fdb\u884c\u4fee\u6539\uff0c\u8bf7\u4f7f\u7528\u5f15\u7528\u4f20\u9012\u3002<\/li>\n<li>\u5982\u679c\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u72ec\u7acb\u7684\u526f\u672c\uff0c\u8bf7\u4f7f\u7528\u503c\u4f20\u9012\u6216\u7ed3\u6784\u5316\u514b\u9686\u7b97\u6cd5\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fjs\u5982\u4f55\u4f20\u9012\u5bf9\u8c61\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u53ef\u4ee5\u4f7f\u7528 javascript \u4f20\u9012\u5bf9\u8c61\u7684\u65b9\u5f0f\u6709\uff1a\u5f15\u7528\u4f20\u9012\u4e00\u4e2a\u5bf9\u8c61\u7684\u526f\u672c\uff0c\u503c\u4f20\u9012\u521b\u5efa\u65b0\u5bf9\u8c61\u5e76\u590d\u5236\u5c5e\u6027\u503c\uff0c\u7ed3\u6784\u5316\u514b\u9686\u7b97\u6cd5\u521b\u5efa\u5b8c\u5168\u72ec\u7acb\u7684\u514b\u9686\u3002\u9009\u62e9\u65b9\u5f0f\u53d6\u51b3\u4e8e\u6240\u9700\u7684\u8bed\u4e49\uff0c\u9700\u8981\u4fee\u6539\u539f\u59cb\u5bf9\u8c61\u65f6\u4f7f\u7528\u5f15\u7528\u4f20\u9012\uff0c\u9700\u8981\u72ec\u7acb\u526f\u672c\u65f6\u4f7f\u7528\u503c\u4f20\u9012\u6216\u7ed3\u6784\u5316\u514b\u9686\u7b97\u6cd5\u3002 \u5982\u4f55\u4f7f\u7528 JavaScript \u4f20\u9012\u5bf9\u8c61 JavaScript \u4e2d\u4f20\u9012\u5bf9\u8c61\u7684\u65b9\u5f0f\u6709\u4ee5\u4e0b\u51e0\u79cd\uff1a 1. \u5f15\u7528\u4f20\u9012\uff08\u4f20\u9012\u5bf9\u8c61\u7684\u5f15\u7528\uff09 \u521b\u5efa\u4e00\u4e2a\u5bf9\u8c61\u7684\u526f\u672c\uff0c\u7136\u540e\u4f20\u9012\u526f\u672c\u3002 \u4efb\u4f55\u5bf9\u526f\u672c\u7684\u66f4\u6539\u90fd\u4f1a\u5f71\u54cd\u539f\u59cb\u5bf9\u8c61\u3002 \/\/ \u521b\u5efa\u4e00\u4e2a\u5bf9\u8c61 const obj = { name: &#8220;John&#8221;, age: 30 }; \/\/ \u4f20\u9012\u526f\u672c const newObj = obj; \/\/ \u4fee\u6539\u526f\u672c newObj.age = 31; \/\/ \u539f\u59cb\u5bf9\u8c61\u4e5f\u88ab\u4fee\u6539 console.log(obj.age); \/\/ \u8f93\u51fa\uff1a31 \u767b\u5f55\u540e\u590d\u5236 2. \u503c\u4f20\u9012\uff08\u4f20\u9012\u5bf9\u8c61\u7684\u5c5e\u6027\u503c\uff09 \u521b\u5efa\u4e00\u4e2a\u65b0\u5bf9\u8c61\uff0c\u7136\u540e\u5c06\u539f\u59cb\u5bf9\u8c61\u7684\u5c5e\u6027\u503c\u590d\u5236\u5230\u65b0\u5bf9\u8c61\u4e2d\u3002 \u4efb\u4f55\u5bf9\u65b0\u5bf9\u8c61\u7684\u66f4\u6539\u90fd\u4e0d\u4f1a\u5f71\u54cd\u539f\u59cb\u5bf9\u8c61\u3002 \/\/ \u521b\u5efa\u4e00\u4e2a\u5bf9\u8c61 const obj = { name: &#8220;John&#8221;, age: 30 }; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-3181","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3181","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=3181"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3181\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=3181"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=3181"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=3181"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}