js 函数传参永远都是值传递,如果参数是对象的话,传的是对象引用的内存地址。
你的问题里 i 指向的是一开始 index 的内存地址,后面执行的 index=15 让 index 指向了新的地址,但是 i 还是指向最初的地址。
如果 index=15 改成 index.data=15 的话,那么 i 会跟着一起变。
参考
http://stackoverflow.com/questions/6605640/javascript-by-reference-vs-by-valueJavascript is always pass by value, but when a variable refers to an object (including arrays), the "value" is a reference to the object.
Changing the value of a variable never changes the underlying primitive or object, it just points the variable to a new primitive or object.
However, changing a property of an object referenced by a variable does change the underlying object.