Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #23553
| Message-ID | <6778903.525aRzo9tQ@PointedEars.de> (permalink) |
|---|---|
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
| Organization | PointedEars Software (PES) |
| Date | 2014-03-12 01:27 +0100 |
| Subject | Re: arr.push(obj); |
| Newsgroups | comp.lang.javascript |
| References | (6 earlier) <253eca00-abda-47da-8388-8a621f36fffd@googlegroups.com> <59661127-bbd4-4eb5-b824-1b4074ccfbd9@googlegroups.com> <531f548b$0$6672$9b4e6d93@newsspool2.arcor-online.net> <c8b312b8-eef9-4f65-abf2-c2725a2d4dc9@googlegroups.com> <531fa123$0$6667$9b4e6d93@newsspool2.arcor-online.net> |
Christoph Michael Becker wrote:
> jonas.thornvall@gmail.com wrote:
>> I try to get the gist of what you saying but for me it is all very
>> confusing. Do you mean something like this?
>>
>> var arr = new Array();
>> for (var i = -500; i <= +500; i ++ )
>> {
>> arr[i] =
>> {
>> count : i,
>> fcolor : 'black',
>> rheight : 100,
>> rwidth : 100,
>> rcolor : 'white'
>> }
>> }
>
> Yes. If you prefer, you can use another variable to store the object
> first, e.g.:
>
> {
> var obj = {...};
> arr[i] = obj;
> }
It is not possible to store objects in variables/properties. It is only
possible to store *references to* objects. References are values. The
difference is important because it emphasizes that there can be several
references to the same object, and there can be unnamed references. [0]
In short: Objects have identity, not name.
The above Block statement is equivalent to
var obj;
{
obj = {...};
arr[i] = obj;
}
which means:
1. Declare a (here: local) variable named “obj”. (This happens *before*
control enters the Block statement, even before all other statements in
that local context are executed.) [1]
2. Create an Object instance, initialize it with the specified properties,
and return a reference to it (“return” with regard to the algorithm only;
understood as the *evaluation value*). [2]
3. Assign to “obj” the reference to the newly created object. [3]
4. Retrieve the reference to the newly created object from “obj” [4] and
store it in (copy it to) the property of the object referred to by “arr”
that is specified by the value of “i” converted to String. (Create
the property if it does not exist and their are no provisions to creating
it. [5] If “arr” is referring to an Array instance, modify the
value of its “length” property value if the value of “i” is an index
value and the value of “i” converted to String, then converted to
unsigned 32-bit integer, is greater than the last index in the array.
[6])
5. Set the evaluation value of the Block statement to “obj” because it is
the evaluation value of the assignment, which is the last statement
in the Block. [7]
_______
[0] <http://ecma-international.org/ecma-262/5.1/#sec-4.2.1>
[1] <http://ecma-international.org/ecma-262/5.1/#sec-12.2>
[2] <http://ecma-international.org/ecma-262/5.1/#sec-11.1.5>
[3] <http://ecma-international.org/ecma-262/5.1/#sec-11.13.1>
[4] <http://ecma-international.org/ecma-262/5.1/#sec-10.3.1>
[5] <http://ecma-international.org/ecma-262/5.1/#sec-8.7.2>
[6] <http://ecma-international.org/ecma-262/5.1/#sec-15.4.5.1>
[7] <http://ecma-international.org/ecma-262/5.1/#sec-12.1>
--
PointedEars
FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
Please do not Cc: me. / Bitte keine Kopien per E-Mail.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
arr.push(obj); jonas.thornvall@gmail.com - 2014-03-10 17:38 -0700
Re: arr.push(obj); jonas.thornvall@gmail.com - 2014-03-10 20:19 -0700
Re: arr.push(obj); jonas.thornvall@gmail.com - 2014-03-10 20:28 -0700
Re: arr.push(obj); jonas.thornvall@gmail.com - 2014-03-10 21:19 -0700
Re: arr.push(obj); Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2014-03-11 06:59 -0300
Re: arr.push(obj); Christoph Michael Becker <cmbecker69@arcor.de> - 2014-03-11 16:02 +0100
Re: arr.push(obj); Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-03-11 16:22 +0000
Re: arr.push(obj); Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2014-03-11 13:32 -0300
Re: arr.push(obj); "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-03-11 10:21 +0100
Re: arr.push(obj); jonas.thornvall@gmail.com - 2014-03-11 03:53 -0700
Re: arr.push(obj); "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-03-11 14:03 +0100
Re: arr.push(obj); jonas.thornvall@gmail.com - 2014-03-11 07:45 -0700
Re: arr.push(obj); "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-03-11 16:24 +0100
Re: arr.push(obj); jonas.thornvall@gmail.com - 2014-03-11 10:40 -0700
Re: arr.push(obj); jonas.thornvall@gmail.com - 2014-03-11 10:51 -0700
Re: arr.push(obj); Christoph Michael Becker <cmbecker69@arcor.de> - 2014-03-11 19:23 +0100
Re: arr.push(obj); jonas.thornvall@gmail.com - 2014-03-11 15:33 -0700
Re: arr.push(obj); "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-03-12 00:37 +0100
Re: arr.push(obj); jonas.thornvall@gmail.com - 2014-03-11 16:46 -0700
Re: arr.push(obj); "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-03-12 01:05 +0100
Re: arr.push(obj); Christoph Michael Becker <cmbecker69@arcor.de> - 2014-03-12 01:40 +0100
Re: arr.push(obj); Christoph Michael Becker <cmbecker69@arcor.de> - 2014-03-12 00:48 +0100
Re: arr.push(obj); jonas.thornvall@gmail.com - 2014-03-11 15:43 -0700
Re: arr.push(obj); jonas.thornvall@gmail.com - 2014-03-11 16:18 -0700
Re: arr.push(obj); "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-03-12 00:39 +0100
Re: arr.push(obj); Christoph Michael Becker <cmbecker69@arcor.de> - 2014-03-12 00:52 +0100
Re: arr.push(obj); Christoph Michael Becker <cmbecker69@arcor.de> - 2014-03-12 00:49 +0100
Re: arr.push(obj); jonas.thornvall@gmail.com - 2014-03-11 17:16 -0700
Re: arr.push(obj); Christoph Michael Becker <cmbecker69@arcor.de> - 2014-03-12 02:07 +0100
Re: arr.push(obj); jonas.thornvall@gmail.com - 2014-03-11 18:13 -0700
Re: arr.push(obj); Christoph Michael Becker <cmbecker69@arcor.de> - 2014-03-13 02:25 +0100
Re: arr.push(obj); Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-03-13 11:03 +0100
Re: arr.push(obj); jonas.thornvall@gmail.com - 2014-03-12 07:46 -0700
Re: arr.push(obj); Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-03-12 01:27 +0100
Re: arr.push(obj); Christoph Michael Becker <cmbecker69@arcor.de> - 2014-03-12 01:44 +0100
Re: arr.push(obj); Christoph Michael Becker <cmbecker69@arcor.de> - 2014-03-11 16:26 +0100
Re: arr.push(obj); Carlos Pedro <carlospedr@gmail.com> - 2014-03-11 09:21 -0700
Re: arr.push(obj); Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-03-11 18:01 +0100
Re: arr.push(obj); Christoph Michael Becker <cmbecker69@arcor.de> - 2014-03-11 19:15 +0100
Re: arr.push(obj); Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-03-11 20:32 +0100
Re: arr.push(obj); Christoph Michael Becker <cmbecker69@arcor.de> - 2014-03-12 01:01 +0100
Re: arr.push(obj); Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-03-12 04:08 +0100
Re: arr.push(obj); Christoph Michael Becker <cmbecker69@arcor.de> - 2014-03-12 18:00 +0100
Re: arr.push(obj); Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2014-03-11 06:24 -0300
Re: arr.push(obj); jonas.thornvall@gmail.com - 2014-03-11 03:47 -0700
Re: arr.push(obj); Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-03-11 15:19 +0000
csiph-web