var v1 = []
var v2 = {};
var v3 = {};
function foo (v1, v2, v3) {
V1 = [1];
v2 = [2];
V3 = {A:3}
}
Foo (v1, v2, v3);
Alert (v1); Blank
Alert (v2); [Object Object]
alert (V3.A); Undefined
/* This shows: v1, V2, V3 have not been changed, V1 is still an array of 0 elements, V2, V3 is still a blank object. (description is not a reference pass)
* However, arrays, objects, etc. are passed by value, which refers to the value of the variable address.
* The values of arrays, objects, etc., are passed by value differently than numbers or strings. Numbers, strings are copied directly into the value, and the array, object is to copy the variable address in the
* Before we let v1, V2, v3 as parameters into the function, there is a copy of the address, these address copies of the point and the outside of the V1, V2, v3 * Address point is the same. But we've assigned values for V1, V2, v3, which means we've changed the point of the address copy to a new array and object. Such internal *V1, V2, V3 and external v1, V2, v3 are completely broken.
* If we do not assign a new value, but manipulate it directly, then it will still be the same array or object that the outer v1, V2, V3 point to.
*/
var v1 = []
var v2 = {};
var v3 = {a:0};
function foo (v1, v2) {
V1.push (1);
v2.a = 2;
v3.a = 3;
}
Foo (v1, v2, v3);
Alert (v1); 1
alert (v2.a); 2
alert (V3.A); 3
Note that when a function with the same name is present, the previous one will be overwritten, and the overwrite occurs during the loading process, and the entire document is equivalent to just the next function at execution time.
function arguments for JavaScript (no reference pass only value pass)