Path: csiph.com!feeder.erje.net!1.eu.feeder.erje.net!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.javascript Subject: Re: array-like objects Date: Sun, 10 Jan 2016 09:03:48 +0100 Organization: PointedEars Software (PES) Lines: 129 Message-ID: <4043891.iRTcHlnhip@PointedEars.de> References: <39241641.QMrUfM43MS@PointedEars.de> <15615987.a6MfTLryX4@PointedEars.de> <4796632.tdeKqXnCYY@PointedEars.de> <2389107.ZQXF91zPQe@PointedEars.de> <9rqv8blasgs3525d1km3qd0ikpm0ng3a49@4ax.com> Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Trace: solani.org 1452413030 13962 eJwFwQkBACAIA8BKThhPHEXoH8E7isHK1WjK4YReSjsGYXVgkgjRhp/tNdxAbj52rFead30EwxBD (10 Jan 2016 08:03:50 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Sun, 10 Jan 2016 08:03:50 +0000 (UTC) User-Agent: KNode/4.14.2 X-User-ID: eJwNxskBgDAMA7CV4ub0OhRn/xFAL6UX6nZUVuTmnjDXM+aA686fFvdVnqOJvc01Az2MxOBUWrJ9NZAIfiWWE/o= Cancel-Lock: sha1:Eq3TjK0iWqCVkicnYUftTJPDQPU= X-NNTP-Posting-Host: eJwNytEVADEEBMCWgrVcOXjSfwm5+R43CidAJ/z6XYWtsc4AzSmOhJ4owcaXqeF/V4xWF7P1AQ/jEJE= Xref: csiph.com comp.lang.javascript:29201 Stefan Ram wrote: > John Harris writes: >> But ECMAScript objects belong to neither of these cases. If you do >> a = b when a holds an object then changing the inside of the object >> held by a also changes the inside of the object held by b even when a >> and b are in different places. This is what's peculiar, or, at least, >> what's different from numbers, strings, etc. > > |< a = Math > > A variable can have a value, and the value of the > variable »a« now is the object that also is known > as »Math«. No, the value of “a” is then a reference to the same object that is referred to by “Math”. *Objects have identity, not name.* Before: {[built-in properties]} <--- Math After: a ---> {[built-in properties]} <--- Math “Math” is actually the name of a built-in property of the global object whose value is a reference to “the Math object”: ,----------------------------. : global object : :----------------------------: a ---> {[built-in properties]} <----:-+ Math : : [more built-in properties] : `----------------------------' > |< b = Math > > Now the value of »b« also is the object also known as »Math«. No, now the value of “b” is a reference to the same object that is already referred to by the values of “Math” and “a”: a ---> {[built-in properties]} <--- Math ^ : : b It really is very simple: *Object references are values.* When an identifier or property access is evaluated, and the result of the evaluation is an object reference, and it is on the right-hand side of a simple assignment, then that object reference is copied and made the value of whatever is on the left-hand side of the assignment. So *there is no algorithmic difference between primitive values and object references with regard to simple assignment*. > This is possible, two different variables /can/ contain the same value. True, but the value thus copied is _not_ the object, but the object *reference*. It would be very inefficient if the entire data of an object would be copied on simple assignment, so that does not happen. Instead, on high level, the object reference is copied, and on low level the address of the location in the heap memory where the object data is stored, would be copied. > |< a.c = 27 > > I set the property »c« of the value of »a« to 27, > thus, I set the property »c« of this object »Math« > to 27. No, you set the property “c” of an object that by now is referred to by the values of “a”, “b“, and “Math”. Before: a ---> {[built-in properties] } <--- Math ^ : : b After: a ---> {[built-in properties], c: 27} <--- Math ^ : : b Now, in theory, you could perform a “delete” operation in succession on “a”, “b”, and “Math”, so that they would no longer refer to said object: 1. {[built-in properties], c: 27} <--- Math ^ : : b 2. {[built-in properties], c: 27} <--- Math 3. {[built-in properties], c: 27} Now the object exists in memory, but nothing refers to it. So it can be marked for garbage collection, and eventually the memory reserved for it can be freed. > |< b.c > |> 27 > > I read the property »c« of the value of »b«, thus, > of this object Math. But that would not be the case if the object were the value copied; so this idea is disproved. -- PointedEars FAQ: | SVN: Twitter: @PointedEars2 | ES Matrix: Please do not cc me. / Bitte keine Kopien per E-Mail.