"Richard Cornford" <> writes:
> Thomas 'PointedEars' Lahn wrote:
>> Richard Cornford wrote:
>>> Being objects they are passed by reference only.
>>
>> No.
>
> You mean they are passed by value? They are not.
No, their reference is passed by value. Using the word "passed by
reference" suggests (well, duh

pass by reference semantics, which
it doesn't have.
> The value of an object is the totality of its state,
I would include its identity too, which is what separates objects from
structs.
> so languages that pass objects by value create a snapshot clone of
> the object and make that available to the function.
.... but when you include identity in the value of the object, then
that would not be correct value passing semantics either.
In fact, objects are not denotable or expressible values (they can't
be assigned to a variable, and you can't write an expression that
evalutes to an object). Only *references* to objects are denotable
and expressible values. The value of an object literal expression
is a reference to the object.
(That objects are neither denotable nor expressible goes for all other
OO languages that I know. (Which is not too many, but still ...
Objects are used (has messages sent to them, to be *really* OO)
through their references.
References are passed by value, as all other values in Javascript.
> but passing the value of a reference is equivalent to passing the
> object referred to by reference (the copy of the value of the
> reference will still refer to the same object instance).
That is not the traditional meaning of "passing by reference". In
that, you pass an l-value, really a reference to a variable, not to
its value. The called function has an alias of the vairable, and can
change its value.
> You would be better off saying that the value of a reference to an
> object is a reference to an object.
To be absolutely pedantic:
Expressions have values and variables refer to values.
If a variable refers to a reference to an object, then the value of
the expression consisting of that variable is the reference to the
object.
When passing the variable by reference, that called function has
access to the variable, and can change what it refers to. The formal
parameter of the function becomes an alias of the variable.
When passing a value by reference, the formal parameter of the
function becomes a new variable referring to the value that was
passed.
> It is significant that even imprecisely worded you are forced to express
> the behaviour of the code in terms of references to objects. In
> javascript all objects are passed by reference.
In Javascript, all object references are passed by value. Objects are
never passed at all.
/L
--
Lasse Reichstein Nielsen -
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'