PageSourceSearch

https://jeremy-ho.vercel.app/assets/js/ee294c4f.8e190983.js

js jeremy-ho.vercel.app collected 2026-10-03 07:08:58 UTC 25,291 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunkcode_fictionist=self.webpackChunkcode_fictionist||[]).push([[163],{28453:(e,l,n)=>{n.d(l,{R:()=>o,x:()=>s});var c=n(96540);const r={},a=c.createContext(r);function o(e){const l=c.useContext(a);return c.useMemo((function(){return"function"==typeof e?e(l):{...l,...e}}),[l,e])}function s(e){let l;return l=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:o(e.components),c.createElement(a.Provider,{value:l},e.children)}},32752:(e,l,n)=>{n.r(l),n.d(l,{assets:()=>j,contentTitle:()=>s,default:()=>d,frontMatter:()=>o,metadata:()=>c,toc:()=>b});const c=JSON.parse('{"id":"series/iThome_2025/day_09","title":"Day09 - Call by Value or Call by Reference?","description":"\u300cCall by value\u300d\u8ddf\u300cCall by reference\u300d\u4e00\u8a5e\u4e4b\u5dee\uff0c\u6982\u5ff5\u537b\u5dee\u4e86\u5341\u842c\u516b\u5343\u91cc\u3002","source":"@site/docs/series/02-iThome_2025/09-day_09.mdx","sourceDirName":"series/02-iThome_2025","slug":"/series/iThome_2025/day_09","permalink":"/docs/series/iThome_2025/day_09","draft":false,"unlisted":false,"tags":[{"inline":true,"label":"JS","permalink":"/docs/tags/js"},{"inline":true,"label":"call by value","permalink":"/docs/tags/call-by-value"},{"inline":true,"label":"call by reference","permalink":"/docs/tags/call-by-reference"},{"inline":true,"label":"call by sharing","permalink":"/docs/tags/call-by-sharing"}],"version":"current","lastUpdatedAt":1766374113000,"sidebarPosition":9,"frontMatter":{"title":"Day09 - Call by Value or Call by Reference?","sidebar_label":"Day09 - Call by Value or Call by Reference?","tags":["JS","call by value","call by reference","call by sharing"],"keywords":["JS","call by value","call by reference","call by sharing"]},"sidebar":"series","previous":{"title":"Day08 - \u9762\u8a66\u5f88\u611b\u8003\u7684\u9589\u5305 (Closure) \u5230\u5e95\u662f\u600e\u9ebc\u4e00\u56de\u4e8b\uff1f","permalink":"/docs/series/iThome_2025/day_08"},"next":{"title":"Day10 - \u53c8\u4e0d\u662f\u5beb\u6587\u7ae0\uff0c\u70ba\u4ec0\u9ebc JS \u4e5f\u6709\u300c!\u300d\u8ddf\u300c?\u300d\u5462\uff1f","permalink":"/docs/series/iThome_2025/day_10"}}');var r=n(74848),a=n(28453);const o={title:"Day09 - Call by Value or Call by Reference?",sidebar_label:"Day09 - Call by Value or Call by Reference?",tags:["JS","call by value","call by reference","call by sharing"],keywords:["JS","call by value","call by reference","call by sharing"]},s=void 0,j={},b=[{value:"Call by value",id:"call-by-value",level:2},{value:"Call by reference",id:"call-by-reference",level:2},{value:"\u4eba\u751f\u7e3d\u662f\u6709\u5404\u7a2e\u4f8b\u5916",id:"\u4eba\u751f\u7e3d\u662f\u6709\u5404\u7a2e\u4f8b\u5916",level:2},{value:"Conclusion",id:"conclusion",level:2}];function i(e){const l={blockquote:"blockquote",br:"br",code:"code",h2:"h2",li:"li",ol:"ol",p:"p",pre:"pre",strong:"strong",...(0,a.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(l.p,{children:["\u300cCall by value\u300d\u8ddf\u300cCall by reference\u300d\u4e00\u8a5e\u4e4b\u5dee\uff0c\u6982\u5ff5\u537b\u5dee\u4e86\u5341\u842c\u516b\u5343\u91cc\u3002",(0,r.jsx)(l.br,{}),"\n","\u8aaa\u5be6\u5728\u7684\uff0c\u9019\u662f\u525b\u5b78 JavaScript \u6642\u901a\u5e38\u4e0d\u6703\u78b0\u5230\u7684\u77e5\u8b58\u9818\u57df\uff0c\u5f80\u5f80\u90fd\u662f\u9762\u8a66\u6642\u88ab\u554f\u5230\u624d\u8d6b\u7136\u767c\u73fe\uff1a\u54c7\uff0cJavaScript \u539f\u4f86\u9084\u6709\u9019\u7a2e\u6771\u897f\u5440\uff01",(0,r.jsx)(l.br,{}),"\n","\u7136\u5f8c\u958b\u59cb\u7814\u7a76\u5f8c\uff0c\u767c\u73fe\u9019\u500b\u6982\u5ff5\u65e9\u65e9\u5730\u5c31\u88ab\u61c9\u7528\u5728\u5e73\u5e38 JavaScript \u958b\u767c\u4e2d\uff0c\u9019\u6642\u6703\u89ba\u5f97\uff0c\u554a\uff0c\u6211\u597d\u50cf\u61c2\u4e86\u3002",(0,r.jsx)(l.br,{}),"\n","\u4f46\u53c8\u7e7c\u7e8c\u5f80\u4e0b\u7814\u7a76\uff0c\u53c8\u767c\u73fe\u9019\u5169\u500b\u6982\u5ff5\u597d\u50cf\u53c8\u6c92\u90a3\u9ebc\u7c21\u55ae\uff0c\u751a\u81f3\u6709\u9ede\u62bd\u8c61...\u3002",(0,r.jsx)(l.br,{}),"\n","\u5766\u767d\u8aaa\uff0c\u6211\u5beb\u9019\u7bc7\u6642\u4e5f\u662f\u770b\u4e86\u5e7e\u4f4d\u5927\u795e\u7684\u6587\u7ae0\u8a66\u5716\u6d88\u5316\u5f8c\u624d\u5beb\u51fa\u4f86\uff0c\u7d50\u5408\u666e\u7f85 JavaScript \u958b\u767c\u8005\u7684\u89c0\u9ede\u8207\u6211\u7684\u89d2\u5ea6\u4f86\u95e1\u8ff0\u4e00\u4e0b\u6211\u7684\u7406\u89e3\u3002"]}),"\n",(0,r.jsx)(l.p,{children:"\u5594\u5c0d\u4e86\uff0c\u9019\u88e1\u6211\u8981\u5f88\u5f37\u8abf\u5730\u8aaa\uff0c\u8acb\u81f3\u5c11\u958b\u500b Replit \u6216\u81ea\u5df1\u7684 IDE \u5be6\u969b\u5c31\u8457\u6211\u7684\u7bc4\u4f8b\u8dd1\u4e00\u6b21\u6703\u66f4\u5bb9\u6613\u7406\u89e3\u4e00\u4e9b\u3002"}),"\n",(0,r.jsx)(l.h2,{id:"call-by-value",children:"Call by value"}),"\n",(0,r.jsx)(l.p,{children:"\u6211\u5011\u5148\u4f86\u8b1b\u8b1b\u6700\u6c92\u554f\u984c\u7684 Call by value\u3002\u5148\u770b\u4e0b\u9762\u9
1019\u9053\u7bc4\u4f8b\uff1a"}),"\n",(0,r.jsx)(l.pre,{children:(0,r.jsx)(l.code,{className:"language-js",children:"let a = 1\nlet b = a\n\nb = 2\n\nconsole.log(a) // 1\nconsole.log(b) // 2\n"})}),"\n",(0,r.jsxs)(l.p,{children:["\u6211\u5011\u53ef\u4ee5\u5f88\u6e05\u695a\u5730\u5f9e\u7d50\u679c\u770b\u5230\uff0c\u5373\u4f7f\u7528\u4e86 ",(0,r.jsx)(l.code,{children:"let b = a"}),"\uff0c\u4f46\u7576\u6211\u66f4\u52d5\u4e86 ",(0,r.jsx)(l.code,{children:"b"})," \u7684\u503c\u6642\uff0c",(0,r.jsx)(l.code,{children:"a"})," \u4e26\u4e0d\u6703\u8ddf\u8457\u6539\u8b8a\uff0c\u5169\u500b\u8b8a\u6578\u662f\u300c\u7368\u7acb\u300d\u7684\u3002",(0,r.jsx)(l.br,{}),"\n","\u300c\u7368\u7acb\u300d\uff0c\u6211\u633a\u559c\u6b61\u9019\u500b\u8a5e\u7684\uff0c\u4ed6\u5e7e\u4e4e\u9053\u76e1 call by value \u7684\u7cbe\u9ad3\u3002",(0,r.jsx)(l.br,{}),"\n","\u5728 call by value \u88e1\uff0c",(0,r.jsx)(l.code,{children:"let b = a"})," \u5be6\u969b\u4e0a\u5728\u505a\u7684\u662f\u9019\u6a23\u4e00\u4ef6\u4e8b\uff1a"]}),"\n",(0,r.jsxs)(l.blockquote,{children:["\n",(0,r.jsxs)(l.p,{children:["\u628a ",(0,r.jsx)(l.code,{children:"a"})," \u7684\u503c\u5f9e ",(0,r.jsx)(l.code,{children:"a"})," \u7684\u8a18\u61b6\u9ad4\u4f4d\u7f6e\u300c\u8907\u88fd\u300d\u7d66\u4e86 ",(0,r.jsx)(l.code,{children:"b"})," \u7684\u8a18\u61b6\u9ad4\u4f4d\u7f6e"]}),"\n"]}),"\n",(0,r.jsxs)(l.p,{children:["\u6240\u4ee5\u5be6\u969b\u4e0a ",(0,r.jsx)(l.code,{children:"a"})," \u8ddf ",(0,r.jsx)(l.code,{children:"b"})," \u662f\u5404\u81ea\u64c1\u6709\u4e00\u500b\u300c\u7368\u7acb\u300d\u7684\u8a18\u61b6\u9ad4\u4f4d\u7f6e\uff0c\u5404\u81ea\u5132\u5b58\u5404\u81ea\u7684\u503c\u3002",(0,r.jsx)(l.br,{}),"\n","\u9019\u6709\u9ede\u50cf\u662f\u4f60\u8ddf\u4f60\u597d\u53cb\u5404\u81ea\u64c1\u6709\u4e00\u68df\u623f\u5b50\uff0c\u4f60\u597d\u53cb\u61f6\u5f97\u505a\u8a2d\u8a08\uff0c\u65bc\u662f\u53bb\u4f60\u5bb6\u6284\u4e86\u4f60\u525b\u8a2d\u8a08\u597d\u7684\u88dd\u6f62\uff0c\u73fe\u5728\u4f60\u5011\u5169\u500b\u7684\u623f\u5b50\u5167\u88dd\u662f\u4e00\u6a23\u7684\uff0c\u4f46\u63a5\u4e0b\u4f86\u4ed6\u958b\u59cb\u6309\u7167\u81ea\u5df1\u7684\u60f3\u6cd5\u53bb\u6539\u88dd\uff0c\u9019\u4e9b\u8b8a\u52d5\u986f\u7136\u4e0d\u6703\u53bb\u5f71\u97ff\u5230\u4f60\u7684\u623f\u5b50\uff0c\u5c0d\u5427\uff1f",(0,r.jsx)(l.br,{}),"\n","\u5927\u6982\u5c31\u662f\u9019\u6a23\u4e00\u500b\u6982\u5ff5\u3002"]}),"\n",(0,r.jsxs)(l.p,{children:["\u800c\u5728 JavaScript \u4e2d\uff0c\u4e00\u5207\u57fa\u790e\u578b\u5225\uff0c\u8af8\u5982 ",(0,r.jsx)(l.code,{children:"number"}),"\u3001",(0,r.jsx)(l.code,{children:"string"}),"\u3001",(0,r.jsx)(l.code,{children:"boolean"}),"\uff0c\u90fd\u662f call by value\u3002"]}),"\n",(0,r.jsx)(l.h2,{id:"call-by-reference",children:"Call by reference"}),"\n",(0,r.jsxs)(l.p,{children:["\u6211\u5011\u5f9e\u4e0a\u9762 call by value \u7684\u7d50\u8ad6\u53ef\u4ee5\u77e5\u9053 JavaScript \u7684\u57fa\u790e\u578b\u5225\u90fd\u662f\u8d70 call by value \u7684\u8def\uff0c\u90a3\u8ab0\u8d70 call by reference \u5c31\u4e0d\u8a00\u800c\u55bb\u4e86\u3002",(0,r.jsx)(l.br,{}),"\n","\u5982\u64ec\u6240\u60f3\uff0cJavaScript \u88e1\uff0c\u4e00\u5207\u7269\u4ef6\u578b\u5225\uff0c\u8af8\u5982 ",(0,r.jsx)(l.code,{children:"object"}),"\u3001",(0,r.jsx)(l.code,{children:"array"}),"\uff0c\u90fd\u662f\u8d70 call by reference\u3002",(0,r.jsx)(l.br,{}),"\n","\u6211\u5011\u4f86\u5f9e object \u7684\u89d2\u5ea6\u770b\u4e00\u4e0b ",(0,r.jsx)(l.code,{children:"let b = a"})," \u9019\u4ef6\u4e8b\u6709\u4e86\u4ec0\u9ebc\u5929\u7ffb\u5730\u8986\u7684\u8b8a\u5316\uff1a"]}),"\n",(0,r.jsx)(l.pre,{children:(0,r.jsx)(l.code,{className:"language-js",children:"let obj1 = {\n  name: \"Jeremy\",\n  age: 28,\n}\n\nlet obj2 = obj1\n\nobj2.age = 29\n\nconsole.log(obj1) // { name: 'Jeremy', age: 29 }\nconsole.log(obj2) // { name: 'Jeremy', age: 29 }\n"})}),"\n",(0,r.jsxs)(l.p,{children:["\u5225\u7ba1\u8b8a\u6578\u540d\u7a31\uff0c\u6211\u53ea\u662f\u628a ",(0,r.jsx)(l.code,{children:"a"})," \u63db\u6210 ",(0,r.jsx)(l.code,{children:"obj1"}),"\uff0c",(0,r.jsx)(l.code,{children:"b"})," \u63db\u6210 ",(0,r.jsx)(l.code,{children:"obj2"}),"\uff0c\u9019\u7d14\u5c6c\u65bc\u4e00\u500b\u500b\u4eba\u64b0\u5beb JavaScript \u7684\u7fd2\u6163\u800c\u5df2\u3002",(0,r.jsx)(l.br,{}),"\n","\u9019\u88e1\u7684\u91cd\u9ede\u5728\u65bc\uff0c\u540c\u6a23\u7684\u908f\u8f2f ",(0,r.jsx)(l.code,{children:"let obj2 = obj1"}),"\uff0c\u7d50\u679c\u537b\u662f\u7576\u66f4\u52d5\u4e86 ",(0,r.jsx)(l.code,{children:"obj2"})," \u7684 ",(0,r.jsx)(l.code,{children:"age"})," \u6642\uff0c",(0,r.jsx)(l.code,{children:"obj1"})," \u7684 ",(0,r.jsx)(l.code,{children:"age"})," \u4e5f\u8ddf\u8457\u8b8a\u4e86\u3002",(0,r.jsx)(l.br,{}),"\n","\u9019\u6642\u4e00\u5b9a\u6709\u4eba\u6703\u8df3\u51fa\u4f86\u8aaa\uff1a\u300c\u56e0\u70ba JavaScript \u7684 object \u88e1\uff0c",(0,r.jsx)(l.code,{children:"let obj2 = obj1"})," \u5be6\u969b\u4e0a\u662f\u628a ",(0,r.jsx)(l.code,{children:"obj1"})," \u7684\u8a18\u61b6\u9ad4\u4f4d\u7f6e\u6307\u7d66\u4e86 ",(0,r.jsx)(l.code,{children:"obj2"})," \u5440\uff01\u300d",(0,r.jsx)(l.br,{}),"\n","\u592a\u597d\u4e86\uff01\u7576\u4f60\u8aaa\u51fa\u9019\u53e5\u8a71\uff0c\u4f60\u5c31\u61c2\u4ec0\u9ebc\u662f JavaScript \u7684 call by reference \u4e86\u3002",(0,r.jsx)(l.br,{}),"\n","\u9019\u88e1\u5f97\u51fa\u4e00\u500b\u7d50\u8ad6\uff0c\u5728 call by reference \u88e1\uff0c",(0,r.jsx)(l.code,{children:"let b = a"})," \u5be6\u969b\u4e0a\u662f\u9019\u6a23\u4e00\u4ef6\u4e8b\uff1a"]}),"\n",(0,r.jsxs)(l.blockquote,{children:["\n",(0,r.jsxs)(l.p,{children:["\u628a ",(0,r.jsx)(l.code,{children:"a"})," \u8b8a\u6578\u7684\u8a18\u61b6\u9ad4\u4f4d\u7f6e\u5206\u4eab\u7d66\u4e86 ",(0,r.jsx)(l.code,{children:"b"})," \u8b8a\u6578"]}),"\n"]}),"\n",(0,r.jsxs)(l.p,{children:["\u77a7\uff0ccall by value \u662f\u300c\u7368\u7acb\u300d\uff0ccall by reference \u662f\u300c\u5206\u4eab\u300d\u3002",(0,r.jsx)(l.br,{}
1),"\n","\u6253\u500b\u6bd4\u65b9\u5c31\u662f\u4f60\u958b\u59cb\u548c\u4f60\u597d\u53cb\u5408\u79df\u4e00\u9593\u623f\u5b50 (\u5927\u5b78\u751f or \u7814\u7a76\u6240\u5e7e\u4e4e\u90fd\u6703\u9019\u6a23\u5e79)\uff0c\u4f60\u5011\u5171\u4eab\u540c\u4e00\u9593\u5c4b\u5b50\u7684\u88dd\u6f62\uff0c\u8ab0\u5c0d\u88dd\u6f62\u6709\u4e86\u8b8a\u52d5\uff0c\u90fd\u6703\u5f71\u97ff\u5230\u5c0d\u65b9\u3002",(0,r.jsx)(l.br,{}),"\n","\u9019\u5c31\u662f call by reference \u7684\u6982\u5ff5\u3002"]}),"\n",(0,r.jsx)(l.h2,{id:"\u4eba\u751f\u7e3d\u662f\u6709\u5404\u7a2e\u4f8b\u5916",children:"\u4eba\u751f\u7e3d\u662f\u6709\u5404\u7a2e\u4f8b\u5916"}),"\n",(0,r.jsxs)(l.p,{children:["\u8b1b\u771f\uff0c\u5982\u679c\u8981\u9762\u8a66\u7684\u8a71\uff0c\u4e0a\u9762\u7684\u6982\u5ff5\u57fa\u672c\u5df2\u7d93\u8db3\u5920\uff0c\u6211\u60f3\u4e5f\u4e0d\u6703\u6709\u9762\u8a66\u5b98\u7e7c\u7e8c\u5f80\u4e0b\u5201 XD",(0,r.jsx)(l.br,{}),"\n","\u6211\u4e5f\u5efa\u8b70\u6e96\u5099\u9762\u8a66\u770b\u5b8c\u4e0a\u9762\u5c31\u597d\uff0c\u6709\u7a7a\u518d\u5f80\u4e0b\u770b\uff0c\u4e0d\u7136\u6211\u6015\u9069\u5f97\u5176\u53cd www\u3002",(0,r.jsx)(l.br,{}),"\n","\u9019\u88e1\u8981\u8b1b\u7684\u662f call by reference \u62bd\u8c61\u7684\u5730\u65b9\uff0c\u5148\u8aaa\uff0c\u53ea\u6709 call by reference \u554a\uff0ccall by value \u5f88\u4e56\u6c92\u6709\u4efb\u4f55\u554f\u984c\u3002"]}),"\n",(0,r.jsxs)(l.p,{children:["\u5df2\u77e5\u7269\u4ef6\u578b\u5225\u8d70\u7684\u662f call by reference \u7684\u8def\uff0c\u6982\u5ff5\u662f\u628a ",(0,r.jsx)(l.code,{children:"a"})," \u8b8a\u6578\u7684\u8a18\u61b6\u9ad4\u4f4d\u7f6e\u5206\u4eab\u7d66\u4e86 ",(0,r.jsx)(l.code,{children:"b"})," \u8b8a\u6578\uff0c\u5169\u8005\u5171\u4eab\u540c\u4e00\u500b\u8a18\u61b6\u9ad4\u4f4d\u7f6e\uff0c\u56e0\u6b64\u7121\u8ad6\u8ab0\u4fee\u6539\u90fd\u662f\u4fee\u6539\u4e86\u540c\u4e00\u500b\u8a18\u61b6\u9ad4\u4f4d\u7f6e\u7684\u503c\u3002\u4f46\u771f\u7684\u4e00\u76f4\u90fd\u662f\u5982\u6b64\u55ce\uff1f",(0,r.jsx)(l.br,{}),"\n","\u770b\u770b\u9019\u500b\u4f8b\u5b50\uff1a"]}),"\n",(0,r.jsx)(l.pre,{children:(0,r.jsx)(l.code,{className:"language-js",children:"let obj1 = {\n  name: \"Jeremy\",\n  age: 28,\n}\n\nlet obj2 = obj1\n\nobj2 = {\n  name: \"Dolores\",\n  age: 500,\n}\n\nconsole.log(obj1) // { name: 'Jeremy', age: 28 }\nconsole.log(obj2) // { name: 'Dolores', age: 500 }\n"})}),"\n",(0,r.jsxs)(l.p,{children:["\u563f\u563f\uff0c\u9177\u5427\uff0c\u6309\u7167 call by reference \u7684\u60f3\u6cd5\uff0c\u4f60\u61c9\u8a72\u6703\u89ba\u5f97\u65e2\u7136\u662f object\uff0c\u90a3 ",(0,r.jsx)(l.code,{children:"let obj2 = obj1"})," \u4e4b\u5f8c\uff0c",(0,r.jsx)(l.code,{children:"obj1"})," \u8ddf ",(0,r.jsx)(l.code,{children:"obj2"})," \u61c9\u8a72\u662f\u5171\u4eab\u540c\u4e00\u500b\u8a18\u61b6\u9ad4\u4f4d\u7f6e\uff0c\u6240\u4ee5\u6211\u628a ",(0,r.jsx)(l.code,{children:"obj2"})," \u6574\u500b\u7269\u4ef6\u5167\u5bb9\u63db\u6389\u6642\uff0c",(0,r.jsx)(l.code,{children:"obj1"})," \u4e5f\u61c9\u8a72\u6703\u8ddf\u8457\u6539\u8b8a\u624d\u5c0d\u3002",(0,r.jsx)(l.br,{}),"\n","\u4f46\u7d50\u679c\u537b\u662f\u5169\u500b object \u537b\u7a81\u7136\u5f7c\u6b64\u300c\u7368\u7acb\u300d\u4e86\u51fa\u4f86\uff0c\u8d70\u4e0a\u4e86 call by value \u7684\u8def\u3002",(0,r.jsx)(l.br,{}),"\n","\u9019\u5c31\u662f\u70ba\u4ec0\u9ebc\u6211\u8aaa call by reference \u662f\u500b\u633a\u62bd\u8c61\u7684\u6982\u5ff5\u3002",(0,r.jsx)(l.br,{}),"\n","\u770b\u5230\u9019\u88e1\u662f\u4e0d\u662f\u6709\u4e9b\u9727\u715e\u715e\u7684 XD",(0,r.jsx)(l.br,{}),"\n","\u9019\u5c31\u662f JavaScript \u5230\u5e95\u6709\u6c92\u6709 call by reference \u767e\u5bb6\u722d\u9cf4\u7684\u5730\u65b9\u3002"]}),"\n",(0,r.jsxs)(l.p,{children:["\u65bc\u662f\u6709\u4e00\u8ad6\u8aaa JavaScript \u5176\u5be6\u5f9e\u982d\u5230\u5c3e\u8d70\u7684\u90fd\u662f call by value\uff0c\u53ea\u662f\u7269\u4ef6\u578b\u5225\u5e73\u5e38\u7684\u884c\u70ba\u8868\u73fe\u5f88\u50cf call by reference\u3002",(0,r.jsx)(l.br,{}),"\n","\u9019\u500b\u8ad6\u8ff0\u7684\u6839\u64da\u4e5f\u662f\u4e0a\u9762 call by reference \u63d0\u5230\u7684\uff0ccall by reference \u662f\u5169\u8b8a\u6578\u5171\u4eab\u540c\u4e00\u500b\u8a18\u61b6\u9ad4\u4f4d\u7f6e\uff0c\u90a3\u7576 ",(0,r.jsx)(l.code,{children:"obj2 = {...}"})," \u6642\uff0c\u9019\u6642\u7406\u61c9\u66f4\u52d5\u7684\u662f\u539f\u8a18\u61b6\u9ad4\u4f4d\u7f6e\u7684\u503c\uff0c\u5c0e\u81f4 ",(0,r.jsx)(l.code,{children:"obj1"})," \u4e5f\u8981\u8ddf\u8457\u6539\u8b8a\u3002\u4f46\u5be6\u969b\u4e0a\u662f ",(0,r.jsx)(l.code,{children:"obj2"})," \u6307\u5411\u4e86\u4e00\u500b\u5168\u65b0\u7684\u8a18\u61b6\u9ad4\u4f4d\u7f6e\uff0c\u9019\u660e\u986f\u4e0d\u7b26\u5408 call by reference \u7684\u6982\u5ff5\u3002",(0,r.jsx)(l.br,{}
1),"\n","\u65bc\u662f\u6709\u4eba\u63d0\u51fa\u9019\u6a23\u7684\u8ad6\u8ff0\uff1a\u300cJavaScript \u5f9e\u982d\u5230\u5c3e\u8d70\u7684\u90fd\u662f call by value\u3002",(0,r.jsx)(l.code,{children:"obj1"})," \u8ddf ",(0,r.jsx)(l.code,{children:"obj2"})," \u662f\u5171\u4eab\u540c\u4e00\u500b\u8a18\u61b6\u9ad4\u4f4d\u7f6e\u7684",(0,r.jsx)(l.strong,{children:"\u503c"}),"\u800c\u4e0d\u662f\u4f4d\u7f6e\u3002\u300d"]}),"\n",(0,r.jsxs)(l.p,{children:["\u63a5\u8457\u51fa\u73fe\u4e86\u7b2c\u4e09\u500b\u540d\u8a5e\uff1a",(0,r.jsx)(l.strong,{children:"call by sharing"}),"\u3002\u5b83\u91cd\u65b0\u95e1\u8ff0\u4e86 JavaScript \u7269\u4ef6\u578b\u5225\u7684\u884c\u70ba\uff1a"]}),"\n",(0,r.jsxs)(l.ol,{children:["\n",(0,r.jsxs)(l.li,{children:[(0,r.jsx)(l.code,{children:"obj1"})," \u8ddf ",(0,r.jsx)(l.code,{children:"obj2"})," \u662f\u5171\u4eab\u540c\u4e00\u500b\u8a18\u61b6\u9ad4\u4f4d\u7f6e\u7684\u503c\uff0c\u800c\u4e0d\u662f\u8a18\u61b6\u9ad4\u4f4d\u7f6e\u3002"]}),"\n",(0,r.jsxs)(l.li,{children:["\u6539\u8b8a\u7269\u4ef6\u5167\u90e8\u5c6c\u6027\u6642\uff0c\u6240\u6709\u6307\u5411\u8a72\u7269\u4ef6\u7684\u8b8a\u6578\u90fd\u6703\u53d7\u5f71\u97ff\u3002ex: ",(0,r.jsx)(l.code,{children:"obj2.age = 29"}),"\u3002"]}),"\n",(0,r.jsxs)(l.li,{children:["\u7576\u628a\u8b8a\u6578\u8ce6\u4e88\u4e00\u500b\u5168\u65b0\u7684 object \u6642\uff0c\u9019\u500b\u8b8a\u6578\u5c31\u6703\u6307\u5411\u4e00\u500b\u5168\u65b0\u7684\u8a18\u61b6\u9ad4\u4f4d\u7f6e\u3002ex: ",(0,r.jsx)(l.code,{children:"obj2 = {...}"}),"\u3002"]}),"\n"]}),"\n",(0,r.jsxs)(l.p,{children:["\u4ec0\u9ebc\u53eb\u300c\u628a\u8b8a\u6578\u8ce6\u4e88\u4e00\u500b\u5168\u65b0\u7684 object\u300d\uff1f",(0,r.jsx)(l.br,{}),"\n","\u5c31\u662f\u50cf\u7bc4\u4f8b\u4e2d\u7684 ",(0,r.jsx)(l.code,{children:"obj2 = {...}"})," \u9019\u6a23\u76f4\u63a5\u7528 object literal \u4f86\u4fee\u6539 object \u7684\u503c\u3002\u5b83\u5be6\u969b\u884c\u70ba\u4e0d\u662f\u66f4\u52d5\u539f\u7269\u4ef6\uff0c\u800c\u662f\u5728\u67d0\u65b0\u8a18\u61b6\u4f4d\u7f6e\u5b58\u4e86\u4e00\u500b\u65b0\u7684\u503c\uff0c\u7136\u5f8c\u628a\u8b8a\u6578\u6307\u5411\u9019\u500b\u65b0\u7684\u8a18\u61b6\u4f4d\u7f6e\u3002",(0,r.jsx)(l.br,{}),"\n","\u4ee5\u7bc4\u4f8b\u4f86\u8aaa\uff0c\u7576 ",(0,r.jsx)(l.code,{children:"obj2 = {...}"})," \u6642\uff0c",(0,r.jsx)(l.code,{children:"obj2"})," \u5c31\u642c\u5bb6\u51fa\u4f86\u300c\u7368\u7acb\u300d\u4e86\u3002"]}),"\n",(0,r.jsx)(l.p,{children:"\u4f46\u6211\u8981\u8aaa\uff0c\u6bd4\u8d77\u8aaa JavaScript \u662f call by value\uff0c\u6211\u66f4\u559c\u6b61\u9019\u6a23\u4e00\u500b\u8aaa\u6cd5\uff1a"}),"\n",(0,r.jsxs)(l.blockquote,{children:["\n",(0,r.jsx)(l.p,{children:"\u7269\u4ef6\u578b\u5225\u5e73\u6642\u7d55\u5927\u591a\u6578\u60c5\u6cc1\u8d70\u7684\u662f call by reference\uff0c\u4f46\u7576\u9047\u5230\u7528 object literal \u4fee\u6539\u7269\u4ef6\u6642\uff0c\u5c31\u6703\u8d70 call by value \u7684\u8def"}),"\n"]}),"\n",(0,r.jsxs)(l.p,{children:["\u6709\u4e9b\u6587\u7ae0\u6703\u7528 method \u4f86\u89e3\u91cb\u9019\u500b call by reference \u8f49\u70ba call by value \u7684\u4f8b\u5916\u60c5\u6cc1\u6216\u662f\u5716\u89e3\u91cb call by sharing\uff0c\u6211\u89ba\u5f97\u76f8\u7576\u96e3\u61c2\uff0c\u7528 object literal \u53cd\u5012\u4e00\u76ee\u77ad\u7136\u3002",(0,r.jsx)(l.br,{}),"\n","\u6211\u5011\u4f86\u770b\u4e00\u4e0b method \u7684\u4f8b\u5b50\uff1a"]}),"\n",(0,r.jsx)(l.pre,{children:(0,r.jsx)(l.code,{className:"language-js",children:"let obj1 = {\n  name: \"Jeremy\",\n  age: 28,\n}\n\nlet obj2 = obj1\n\nfunction changeObj(obj) {\n  obj = {\n    name: \"Dolores\",\n    age: 500,\n  }\n\n  return obj\n}\n\nchangeObj(obj2)\n\nconsole.log(obj1) // { name: 'Jeremy', age: 28 }\nconsole.log(obj2) // { name: 'Jeremy', age: 28 }\n"})}),"\n",(0,r.jsxs)(l.p,{children:["\u9019\u88e1\u5f88\u6709\u8da3\u7684\uff0c",(0,r.jsx)(l.code,{children:"console.log(obj2)"})," \u6703\u807d\u5230\u5169\u7a2e\u7b54\u6848\uff0c\u6309\u7167\u524d\u9762\u7684\u6982\u5ff5\uff0c\u6211\u731c\u591a\u6578\u4eba\u6703\u8aaa\u7b54\u6848\u662f ",(0,r.jsx)(l.code,{children:"{ name: 'Dolores', age: 500 }"}),"\uff0c\u4f46\u5be6\u969b\u4e0a\u7d50\u679c\u5982\u7bc4\u4f8b\u6240\u793a\uff0cobject \u7684\u503c\u5176\u5be6\u4e26\u6c92\u6709\u88ab\u6539\u8b8a\u3002",(0,r.jsx)(l.br,{}),"\n","\u4f46\u5982\u679c\u6211\u5011\u628a ",(0,r.jsx)(l.code,{children:"changeOb
1j(obj2)"})," \u6539\u6210 ",(0,r.jsx)(l.code,{children:"obj2 = changeObj(obj2)"}),"\uff0c\u90a3\u7d50\u679c\u5c31\u6703\u662f ",(0,r.jsx)(l.code,{children:"{ name: 'Dolores', age: 500 }"})," \u4e86\u3002"]}),"\n",(0,r.jsx)(l.pre,{children:(0,r.jsx)(l.code,{className:"language-js",children:"let obj1 = {\n  name: \"Jeremy\",\n  age: 28,\n}\n\nlet obj2 = obj1\n\nfunction changeObj(obj) {\n  obj = {\n    name: \"Dolores\",\n    age: 500,\n  }\n\n  return obj\n}\n// highlight-next-line\nobj2 = changeObj(obj2)\n\nconsole.log(obj1) // { name: 'Jeremy', age: 28 }\nconsole.log(obj2) // { name: 'Dolores', age: 500 }\n"})}),"\n",(0,r.jsxs)(l.p,{children:["\u4f46\u80fd\u8aaa\u9019\u88e1\u4f7f\u7528 object literal \u7684\u65b9\u5f0f\u4f86\u66f4\u52d5 object \u5c31\u662f call by value \u7684\u6982\u5ff5\u5c31\u6d88\u5931\u4e86\u55ce\uff1f\u5176\u5be6\u4e0d\u7136\u3002",(0,r.jsx)(l.br,{}),"\n",(0,r.jsx)(l.code,{children:"changeObj(obj2)"})," \u9019\u500b method \u4e00\u57f7\u884c\uff0c\u5176\u5be6\u5c31\u5df2\u7d93\u5728\u5efa\u7acb\u4e86\u4e00\u500b\u65b0\u7684\u8a18\u61b6\u9ad4\u4f4d\u7f6e\u5b58\u4e86 ",(0,r.jsx)(l.code,{children:"{ name: 'Dolores', age: 500 }"}),"\uff0c\u53ea\u662f\u73fe\u5728\u9019\u500b\u8a18\u61b6\u9ad4\u4f4d\u7f6e\u662f\u7531 method \u5167\u7684\u8b8a\u6578 ",(0,r.jsx)(l.code,{children:"obj"})," \u6240\u6307\u5411\u800c\u5df2\u3002",(0,r.jsx)(l.br,{}),"\n","\u6240\u4ee5\u7576\u6211\u5011\u628a ",(0,r.jsx)(l.code,{children:"obj2 = changeObj(obj2)"})," \u6642\uff0c",(0,r.jsx)(l.code,{children:"obj2"})," \u5c31\u6307\u5411\u4e86\u9019\u500b\u65b0\u7684\u8a18\u61b6\u9ad4\u4f4d\u7f6e\uff0c\u63db\u53e5\u8a71\u8aaa\uff0c",(0,r.jsx)(l.code,{children:"obj2"})," \u5c31\u9019\u6a23\u6c34\u9748\u9748\u7684\u300c\u642c\u5bb6\u300d\u4e86~",(0,r.jsx)(l.br,{}),"\n","\u6240\u4ee5 object literal \u7684\u65b9\u5f0f\u4f86\u66f4\u52d5 object \u662f call by value \u7684\u6982\u5ff5\u9084\u662f\u6709\u597d\u597d\u9ad4\u73fe\u5728 method \u4e0a\u7684\u3002"]}),"\n",(0,r.jsx)(l.p,{children:"\u6700\u5f8c\u6211\u5011\u518d\u505a\u4e00\u500b\u8a66\u9a57\uff0c\u5982\u679c\u628a method \u66f4\u52d5 object \u7684\u65b9\u5f0f\u6539\u6210\u4e0d\u662f object literal \u5462\uff1f"}),"\n",(0,r.jsx)(l.pre,{children:(0,r.jsx)(l.code,{className:"language-js",children:"let obj1 = {\n  name: \"Jeremy\",\n  age: 28,\n}\n\nlet obj2 = obj1\n\nfunction changeObj(obj) {\n  obj.name = \"Dolores\"\n  obj.age = 500\n}\n\nchangeObj(obj2)\n\nconsole.log(obj1) // { name: 'Dolores', age: 500 }\nconsole.log(obj2) // { name: 'Dolores', age: 500 }\n"})}),"\n",(0,r.jsxs)(l.p,{children:["\u77a7\uff0c\u7d50\u679c\u53c8\u56de\u5230\u4e86 call by reference \u7684\u6982\u5ff5\uff0c",(0,r.jsx)(l.code,{children:"obj1"})," \u8ddf ",(0,r.jsx)(l.code,{children:"obj2"})," \u4e00\u8d77\u66f4\u52d5\u4e86\u3002"]}),"\n",(0,r.jsx)(l.h2,{id:"conclusion",children:"Conclusion"}),"\n",(0,r.jsxs)(l.p,{children:["\u770b\u5230\u9019\u88e1\u7684\uff0c\u6211\u5e0c\u671b\u4e0d\u8981\u88ab\u524d\u4e00\u7bc0\u7684\u5167\u5bb9\u7d66\u641e\u6688\u4e86 XD",(0,r.jsx)(l.br,{}),"\n","\u8aaa\u771f\u7684 JavaScript \u5f88\u591a\u62bd\u8c61\u7684\u5730\u65b9\uff0c\u4e0d\u53ea call by value \u8ddf call by reference\u300d\u4e00\u8a5e\u4e4b\u5dee\uff0c\u6982\u5ff5\u537b\u5dee\u4e86\u5341\u842c\u516b\u5343\u91cc\u3002"]}),"\n",(0,r.jsxs)(l.p,{children:["\u5982\u679c\u4f60\u662f\u70ba\u4e86\u9762\u8a66\u7684\uff0c\u6211\u6703\u5efa\u8b70\u4f60\u770b\u524d\u5169\u7bc0\uff0c\u8a18\u4e00\u4e0b call by value \u8ddf call by reference \u7684\u6982\u5ff5\u5c31\u597d\u3002",(0,r.jsx)(l.br,{}),"\n","\u4f60\u53ea\u8981\u8a18\u5f97\u5169\u500b\u6982\u5ff5\uff1a"]}),"\n",(0,r.jsxs)(l.ol,{children:["\n",(0,r.jsxs)(l.li,{children:["Call by value\uff1a\u628a ",(0,r.jsx)(l.code,{children:"a"})," \u7684\u503c\u5f9e ",(0,r.jsx)(l.code,{children:"a"})," \u7684\u8a18\u61b6\u9ad4\u4f4d\u7f6e\u300c\u8907\u88fd\u300d\u7d66\u4e86 ",(0,r.jsx)(l.code,{children:"b"})," \u7684\u8a18\u61b6\u9ad4\u4f4d\u7f6e\uff0c\u5169\u8b8a\u6578\u662f\u300c\u7368\u7acb\u300d\u7684\u3002\u4e00\u5207\u57fa\u790e\u578b\u5225\u90fd\u662f\u8d70 call by value\u3002"]}),"\n",(0,r.jsxs)(l.li,{children:["Call by reference\uff1a\u628a ",(0,r.jsx)(l.code,{children:"a"})," \u8b8a\u6578\u7684\u8a18\u61b6\u9ad4\u4f4d\u7f6e\u5206\u4eab\u7d66\u4e86 ",(0,r.jsx)(l.code,{children:"b"})," \u8b8a\u6578\uff0c\u5169\u8b8a\u6578\u662f\u300c\u5171\u4eab\u300d\u4e00\u500b\u8a18\u61b6\u9ad4\u4f4d\u7f6e\u7684\uff0c\u56e0\u6b64\u7121\u8ad6\u8ab0\u66f4\u52d5\u4e86\u503c\uff0c\u53e6\u4e00\u500b\u8b8a\u6578\u90fd\u6703\u53d7\u5230\u5f71\u97ff\u3002\u4e00\u5207\u7269\u4ef6\u578b\u5225\u90fd\u662f\u8d70 call by reference\u3002"]}),"\n"]}),"\n",(0,r.jsxs)(l.p,{children:["\u9664\u975e\u9762\u8a66\u5b98\u771f\u7684\u5f88\u60f3\u8a0e\u8ad6\u6280\u8853\uff0c\u6216\u662f\u4f60\u9762\u7684\u662f senior\uff0c\u90a3\u6211\u89ba\u5f97\u624d\u6709\u6a5f\u6703\u8a0e\u8ad6\u5230 call by reference \u7684\u90a3\u500b\u4f8b\u5916\u72c0\u6cc1\u3002",(0,r.jsx)(l.br,{}),"\n","\u90a3\uff0c\u6240\u4ee5 JavaScript \u5230\u5e95\u6709\u6c92\u6709 call by reference\uff1f\u9084\u662f\u7528 c
1all by sharing \u66ff\u4ee3 call by reference\uff1f\u4ea6\u6216\u662f\u901a\u901a\u8d70 call by value\uff1f",(0,r.jsx)(l.br,{}),"\n","Well\uff0c\u6211\u89ba\u5f97\u5176\u5be6\u90fd\u5c0d\uff0c\u6230\u570b\u6642\u671f\u767e\u5bb6\u722d\u9cf4\uff0c\u6709\u54ea\u4e00\u5bb6\u771f\u7684\u5b8c\u5168\u6b63\u78ba\u7684\u5462\uff1f"]})]})}function d(e={}){const{wrapper:l}={...(0,a.R)(),...e.components};return l?(0,r.jsx)(l,{...e,children:(0,r.jsx)(i,{...e})}):i(e)}}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.