Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #13083

Re: call by reference

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
From Asen Bozhilov <asen.bozhilov@gmail.com>
Newsgroups comp.lang.javascript
Subject Re: call by reference
Date Tue, 27 Mar 2012 05:15:35 -0700 (PDT)
Organization http://groups.google.com
Lines 55
Message-ID <16809571.1415.1332850535967.JavaMail.geo-discussion-forums@vbex14> (permalink)
References <jkhrtr$i06$1@news.albasani.net> <XnsA01FA6D1ADCF9eejj99@194.109.133.133>
NNTP-Posting-Host 84.40.76.49
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
X-Trace posting.google.com 1332851347 18095 127.0.0.1 (27 Mar 2012 12:29:07 GMT)
X-Complaints-To groups-abuse@google.com
NNTP-Posting-Date Tue, 27 Mar 2012 12:29:07 +0000 (UTC)
In-Reply-To <XnsA01FA6D1ADCF9eejj99@194.109.133.133>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=84.40.76.49; posting-account=7Fm93QoAAADJLfahesQYQvMxF-JssE8W
User-Agent G2/1.0
X-Received-Bytes 2716
Xref csiph.com comp.lang.javascript:13083

Show key headers only | View raw


Evertjan:

> JavaScript DOES support call-by-reference.
> 
> All objects are called by reference:

This is long discussed topic. Your terminology even and it is not correct seems more closer to the point. JavaScript uses the evaluation strategy called "Call by sharing". 
<URL: http://en.wikipedia.org/wiki/Evaluation_strategy#Call_by_sharing> 

It is often mistaken with  "Call by reference", but it slightly differ: 

"The semantics of call-by-sharing differ from call-by-reference in that assignments to function arguments within the function aren't visible to the caller (unlike by-reference semantics)[citation needed], so e.g. if a variable was passed, it is not possible to simulate an assignment on that variable in the caller's scope. However since the function has access to the same object as the caller (no copy is made), mutations to those objects, if the objects are mutable, within the function are visible to the caller, which may appear to differ from call-by-value semantics."   

 
> <script type='text/javascript'>
> 
> var myObj = {};
> 
> myObj.myValue = 7;
> alert(myObj.myValue); // 7
> 
> function f(a) {
>   a.myValue = 33;
> };
> 
> f(myObj);
> alert(myObj.myValue); // 33
> 
> </script>

It does not prove your point. 

function f(o) {
    o.foo = 10;
    o = {foo : 0};
}

var obj = {foo : 5};
f(obj);

print(obj.foo); //10

This example shows that JavaScript does not use "Call by reference" if it used the value of `foo` would be 0 instead. The example shows "Call by sharing" strategy. 

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


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