howa wrote:
Consider a simple example, e.g.
var a = {
'a': 'b',
'c': 'd'
}
This is initializing an Object object and assigning the reference to it to `a'.
var k = a;
1. Is it assign by value (copying) or by reference)
As (object) references are values in ECMAScript implementations, you are
asking the wrong question.
You are assigning the reference value stored in `a' to `k' here. So after
that assignment, `k' refers to the same object as `a'.
2. If it is by value/reference, how to make them assign by reference/
value
You can only "copy" references to objects as you "copy" any other value; you
cannot "copy" the object itself. However, you can "copy" certain property
values from one object to another, or you can have one object inherit
properties from another through the prototype chain. But that is different
from copying the object; objects have identity.
PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>