Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #13018
| From | BGB <cr88192@hotmail.com> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: call by reference |
| Date | 2012-03-23 15:23 -0700 |
| Organization | albasani.net |
| Message-ID | <jkit8k$q07$1@news.albasani.net> (permalink) |
| References | (1 earlier) <XnsA01FA6D1ADCF9eejj99@194.109.133.133> <97d44dea-bfe6-4300-bd31-31c78103a9d7@er9g2000vbb.googlegroups.com> <XnsA01FD26DBDFD0eejj99@194.109.133.133> <37mpm7t5g4or5h5n14sbf7p66p44bv0obe@4ax.com> <XnsA01FE2F36A698eejj99@194.109.133.133> |
On 3/23/2012 2:18 PM, Evertjan. wrote:
> Gene Wirchenko wrote on 23 mrt 2012 in comp.lang.javascript:
>
>>> Reference in my book, in Javascript or any other language,
>>> is transferring the variable-pointer or object-pointer
>>> and not the value.
>>
>> Nope.
>
> "Nope"?
> Could you speak normal English in this international NG, please.
>
> And why?
> Do you know my book?
>
>> It is passing in such a way that the actual parameter can
>> be changed (the one in the call).
>
> "actual"? Are there non-actual parameters in javascript?
>
> Please explain what we should call the passing of an object in
> javascript.
>
> == Is it by value?
>
> No, because you cannot change the object as such.
>
if we define an object as a "reference type", then the "object
reference" is being passed by-value.
> == Is it by reference?
>
> Yes, because you can change the object's properties and methods,
> which are in fact the "values" of an object.
>
this only goes so far as to say that one has a reference to the object's
data (IOW, it is not being "physically" passed in the same manner as,
say, a C struct).
> So I maintain that objects are passed by reference.
>
"passing by reference" generally refers to the idea that it is the
variable itself which is being passed by reference.
when passing an object, one is passing a reference to the object, and
not to the variable holding the object.
these sorts of distinctions are important.
> <script type='text/javascript'>
>
> var a = {x:9};
> var b = {y:19};
>
> function increment(p,z) {
> p[z]++;
> };
>
> increment(a,'x');
>
> increment(b,'y');
>
> alert(a.x); // 10
> alert(b.y); // 20
>
>
> </script>
>
this example does not show "pass by reference", it shows that one has "a
reference to the object" (which is itself passed "by value").
what *would* show "pass by reference", would be if this were to work:
function increment(x)
{ x++; }
var x=3;
increment(x);
alert(x); // 4
given it does not (one will still see 3 here), one can conclude that it
is not using "pass by reference".
this is in-fact the default behavior in some languages (such as VB and
Perl), but is relatively uncommon (most languages use "pass by value"
instead, despite objects generally being "references").
http://en.wikipedia.org/wiki/Pass_by_reference#Call_by_reference
note that many languages that do support pass-by-reference, do so via
explicit syntax, for example:
foo(&x);
foo(ref x);
foo(out x);
...
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
call by reference Andreas Bergmaier <andber93@web.de> - 2012-03-23 13:56 +0100
Re: call by reference Scott Sauyet <scott.sauyet@gmail.com> - 2012-03-23 07:10 -0700
Re: call by reference "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-03-23 15:23 +0000
Re: call by reference Scott Sauyet <scott.sauyet@gmail.com> - 2012-03-23 09:28 -0700
Re: call by reference "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-03-23 19:41 +0000
Re: call by reference Gene Wirchenko <genew@ocis.net> - 2012-03-23 13:43 -0700
Re: call by reference "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-03-23 21:18 +0000
Re: call by reference BGB <cr88192@hotmail.com> - 2012-03-23 15:23 -0700
Re: call by reference Gene Wirchenko <genew@ocis.net> - 2012-03-23 15:27 -0700
Re: call by reference "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-03-24 00:19 +0000
Re: call by reference Norman Peelman <npeelmandog@cfl.rr.com> - 2012-03-28 06:43 -0400
Re: call by reference "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-03-28 14:50 +0000
Re: call by reference Aatu Koskensilta <aatu.koskensilta@uta.fi> - 2012-03-28 18:06 +0300
Re: call by reference "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-03-28 15:57 +0000
Re: call by reference Eric Bednarz <bednarz@fahr-zur-hoelle.org> - 2012-03-28 23:22 +0200
Re: call by reference "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-03-29 07:18 +0000
Re: call by reference Eric Bednarz <bednarz@fahr-zur-hoelle.org> - 2012-03-29 13:34 +0200
Re: call by reference David Mark <dmark.cinsoft@gmail.com> - 2012-03-29 18:30 -0700
Re: call by reference Eric Bednarz <bednarz@fahr-zur-hoelle.org> - 2012-04-03 00:09 +0200
Re: call by reference David Mark <dmark.cinsoft@gmail.com> - 2012-04-02 17:43 -0700
Re: call by reference Robert Baer <robertbaer@localnet.com> - 2012-03-30 00:49 -0800
Re: call by reference Scott Sauyet <scott.sauyet@gmail.com> - 2012-03-28 13:33 -0700
Re: call by reference John G Harris <john@nospam.demon.co.uk> - 2012-03-24 11:34 +0000
Re: call by reference Aatu Koskensilta <aatu.koskensilta@uta.fi> - 2012-03-26 22:46 +0300
Re: call by reference Gene Wirchenko <genew@ocis.net> - 2012-03-26 18:38 -0700
Re: call by reference Aatu Koskensilta <aatu.koskensilta@uta.fi> - 2012-03-27 05:13 +0300
Re: call by reference Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-03-27 18:31 +0200
Re: call by reference Aatu Koskensilta <aatu.koskensilta@uta.fi> - 2012-03-27 21:31 +0300
Re: call by reference Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-03-27 21:03 +0200
Re: call by reference "Ross A. Finlayson" <ross.finlayson@gmail.com> - 2012-04-10 22:03 -0700
Re: call by reference Scott Sauyet <scott.sauyet@gmail.com> - 2012-03-25 07:34 -0700
Re: call by reference "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-03-25 15:53 +0000
Re: call by reference Asen Bozhilov <asen.bozhilov@gmail.com> - 2012-03-27 05:15 -0700
Re: call by reference BGB <cr88192@hotmail.com> - 2012-03-23 13:03 -0700
Re: call by reference Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-03-23 23:02 +0100
Re: call by reference John G Harris <john@nospam.demon.co.uk> - 2012-03-24 11:40 +0000
csiph-web