From: Richard Cornford on
On May 19, 4:54 pm, Ry Nohryb wrote:
<snip>
> WRT objects, you're always passing references, by copy,
> but references, unlike when passing primitive values.

How can you tell? Specifically, how can you tall that primitives are
not implemented as structures somewhere in memory and that the values
assigned to object properties/valuables are not references to those
structures; that copying a primitive 'value' from one variable to
another does not actually involve copying a reference?

The thing is that you cannot tell. Javascript offers no operators that
will allow you to modify a primitive, so while you can observe the
modification to an object and conclude that there must be some
'referencing' mechanism that has all values that are objects
'referring' to the single object the inability to do the same test on
the primitives does not excused the possibility that exactly the same
implementation mechanism has been applied to them.

Richard.
From: Ry Nohryb on
On May 19, 6:22 pm, Richard Cornford <Rich...(a)litotes.demon.co.uk>
wrote:
> On May 19, 4:54 pm, Ry Nohryb wrote:
> <snip>
>
> > WRT objects, you're always passing references, by copy,
> > but references, unlike when passing primitive values.
>
> How can you tell? Specifically, how can you tall that primitives are
> not implemented as structures somewhere in memory and that the values
> assigned to object properties/valuables are not references to those
> structures; that copying a primitive 'value' from one variable to
> another does not actually involve copying a reference?
>
> The thing is that you cannot tell. Javascript offers no operators that
> will allow you to modify a primitive, so while you can observe the
> modification to an object and conclude that there must be some
> 'referencing' mechanism that has all values that are objects
> 'referring' to the single object the inability to do the same test on
> the primitives does not excused the possibility that exactly the same
> implementation mechanism has been applied to them.

Well, yes, you're right. The observable behaviour must be as if they
were passed by copy, and it is. But then, it's observable as well that
in V8 at least the strings are not passed by copy, because, if you
copy a 100MB string to 8 different vars, V8 does *not* use 800 MB,
even though looking at the specs they should have been duplicated.
It's when you add a single char to them that they are duplicated.
--
Jorge.
From: Ry Nohryb on
On May 19, 5:28 pm, Ry Nohryb <jo...(a)jorgechamorro.com> wrote:
>
> (...) and C -being a lower lever language- (...)

s/lever/level/
--
Jorge
From: Thomas 'PointedEars' Lahn on
Ry Nohryb wrote:

> Thomas 'PointedEars' Lahn wrote:
>> Tim Streater wrote:
>> > Ry Nohryb wrote:
>> >> you can't avoid to pass objects by reference.
>>
>> No, you pass the reference value to the function (by value). How many
>> times has that been explained to you already, Jorge Chamorro, albeit your
>> not using a pseudonym back then?
>
> "PointedEars" is to Thomas Lahn what "Ry Nohryb" ( === rot13("El
> Abuelo") ) is to Jorge Chamorro: a nick name (not a pseudo-name).

No, I post with my real name, the nick name only in-between. By comparison,
you do not post with your real name, you use your nick name as a pseudonym.
And you know that.

> My name is as clear as an unmuddied lake,

It is not, and you know it. Why else would you have changed your From
header?

>> /* Firebug 1.5.4: Object { j="Simpson"} */
>> (function (o) { o.j = "Simpson"; return o; }({}))
>>
>> > You are not passing the object, you are passing a *pointer* to the
>> > object.
>>
>> No, think twice. If it was a pointer, which it is not, it would work
>> like call-by-reference: it would be possible to overwrite the object by
>> assigning to (the identifier of) the argument (since this would require
>> implicit pointer referencing we could reasonably assume implicit pointer
>> dereferencing).
>
> To begin with pointers and C are at a much lower level than JS.

You are not paying attention. I said *if* that were pointers then what I
describe would happen. I have also said explicitly that they are not, which
makes the rest of your babbling quite irrelevant.

> In JS, the object that the reference points to can be overwritten,

No, it cannot. It can only be modified, i.e. it can be augmented with
properties, properties can be deleted, and property values can be changed.
You are not paying attention, for an example that proves that has already
been posted.

> My point since day 1, is that an object is said to be passed-by-
> reference when instead of copying it (as in pass-by-copy), what gets
> passed is a *reference* that points to it, as is the case in JS.

No, that is _not_ how pass-by-reference (better: call-by-reference) is
defined. And therefore call-by-reference simply does not happen in
ECMAScript implementations (to date).


PointedEars
--
Danny Goodman's books are out of date and teach practices that are
positively harmful for cross-browser scripting.
-- Richard Cornford, cljs, <cife6q$253$1$8300dec7(a)news.demon.co.uk> (2004)
From: Ry Nohryb on
On May 19, 10:35 pm, Thomas 'PointedEars' Lahn <PointedE...(a)web.de>
wrote:
> Ry Nohryb wrote:
> > Thomas 'PointedEars' Lahn wrote:
>
> (idiocies about my nick snipped)
>
> (...)
> You are not paying attention.  I said *if* that were pointers then what I
> describe would happen.  I have also said explicitly that they are not, which
> makes the rest of your babbling quite irrelevant.

Had you read what I posted, you would know why if that were pointers,
what you describe(d) is not what would happen.

> > In JS, the object that the reference points to can be overwritten,
>
> No, it cannot.  It can only be modified, i.e. it can be augmented with
> properties, properties can be deleted, and property values can be changed..  
> You are not paying attention, for an example that proves that has already
> been posted.

You are not paying attention: of course the object that it refers to
can be completely overwritten.

And you're misunderstanding this: when you have a reference that
points to object A and want it to point to object B, its value must
change, but that won't change automagically any other copies of the
reference to object A in existence, but that does not make it any less
of a reference.

> > My point since day 1, is that an object is said to be passed-by-
> > reference when instead of copying it (as in pass-by-copy), what gets
> > passed is a *reference* that points to it, as is the case in JS.
>
> No, that is _not_ how pass-by-reference (better: call-by-reference) is
> defined.  And therefore call-by-reference simply does not happen in
> ECMAScript implementations (to date).

You can repeat that as many times as you want, but in JS objects are
passed by reference exactly as in C. It's just that most script-
kiddies are too young -and lacking in C- to comprehend it.
--
Jorge.