Evertjan.
2/26/2016 1:15:00 PM
Scott Sauyet <scott.sauyet@gmail.com> wrote on 26 Feb 2016 in
comp.lang.javascript:
> On Friday, February 26, 2016 at 6:50:56 AM UTC-5, Andrew Poulos wrote:
>> Say I have this object
>>
>> var foo {
>> "name":"bar"
>> "width":600
>> }
>>
>> and I want to add another element that references a value within the
>> object itself. eg
>>
>> var foo {
>> "name":"bar"
>> "width":600,
>> "height": width * 2
>> }
>
> One approach:
>
> var foo = (function() {
> var width = 600;
> return {
> name: 'bar',
> width: width,
> height: 2 * width
> }
> }());
var foo = { 'name': 'bar','width': 600 };
foo.height = foo.width * 2;
or:
var foo = {};
foo.name = 'bar';
foo.width = 600;
foo.height = foo.width * 2;
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)