:
var foo = bar;
- . , foo , bar. , , bar 0xFF, foo 0xFF.
, bar foo - , .
, , bar foo, .
bar.prop = "something entirely different"; // affects foo.prop also
, :
Assignment only changes what the name of the object is bound to, and does not affect any other objects.
, , bar , foo.
bar = "no longer an object";
, :
Javascript is always pass by value, but when a variable refers to an object (including arrays), the "value" is a reference to the object.
:
function f(obj1, obj2)
{
obj1.prop = 10;
obj2 = {prop: 20};
}
var bar = {prop: 1};
var foo = {prop: 2};
f(bar, foo);
console.log("bar.prop: " + bar.prop + ", foo.prop: " + foo.prop);
: bar.prop: 10, foo.prop: 2. f, obj1 , bar, obj2 , foo. , , f , obj2 = {prop: 20}; obj2 not foo.
, the "value" is a reference to an object , , .