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


Groups > comp.lang.javascript > #29705

Re: Refer object within itself

Path csiph.com!news.mixmin.net!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail
From "Christoph M. Becker" <cmbecker69@arcor.de>
Newsgroups comp.lang.javascript
Subject Re: Refer object within itself
Date Fri, 26 Feb 2016 16:43:17 +0100
Organization solani.org
Lines 32
Message-ID <naprqc$66b$1@solani.org> (permalink)
References <76ydnVazm-uPoU3LnZ2dnUU7-TGdnZ2d@westnet.com.au>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 7bit
X-Trace solani.org 1456501388 6347 eJwNysEBwCAIA8CVJECUcQBl/xHae58rhb2NTvPxiRa84QUZYhKgX1bBnzqgeh/2HOsM5A4LE8s8t/9okQk16V5R/JOfl9x2otZ46ipZ+ABVaB0L (26 Feb 2016 15:43:08 GMT)
X-Complaints-To abuse@news.solani.org
NNTP-Posting-Date Fri, 26 Feb 2016 15:43:08 +0000 (UTC)
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0
X-User-ID eJwFwYEBwCAIA7CXhtJSznEg/59ggk1jhRN0DIaIm9XxTe5y9aKsrNRoO5EK2vXWn0snzvABFs8Q9g==
In-Reply-To <76ydnVazm-uPoU3LnZ2dnUU7-TGdnZ2d@westnet.com.au>
Cancel-Lock sha1:7a39HEsy1h3P/DkkCwousGRHpCY=
X-NNTP-Posting-Host eJwNzMEBACEIxMCWQHGFcgCX/ku4e2YeORuKvoYDO3MmTHYSU4XIfoO8nlm3bpogVog2hKU7qKS/TQ1ff5PQx3b1lCM/8R+YAXi9TBdbTOYDvLQepQ==
Xref csiph.com comp.lang.javascript:29705

Show key headers only | View raw


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
> }
>
> How do I reference to the object itself within the object?

AFAIK, you can't.  You may consider to employ a "constructor" function
instead:

  function makeFoo(name, width) {
      return {name: name, width: width; height: 2 * width};
  }

  makeFoo("bar", 600);

-- 
Christoph M. Becker

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


Thread

Refer object within itself Andrew Poulos <ap_prog@hotmail.com> - 2016-02-26 22:50 +1100
  Re: Refer object within itself Scott Sauyet <scott.sauyet@gmail.com> - 2016-02-26 04:51 -0800
    Re: Refer object within itself "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-02-26 14:15 +0100
  Re: Refer object within itself "Christoph M. Becker" <cmbecker69@arcor.de> - 2016-02-26 16:43 +0100
    Re: Refer object within itself Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-02-26 19:25 +0100
  Re: Refer object within itself Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-02-26 19:23 +0100
  Refer object within itself Ram Tobolski <ramtob@gmail.com> - 2016-02-28 10:06 -0800
    Re: Refer object within itself "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-02-28 23:07 +0100
      Re: Refer object within itself "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-02-28 23:23 +0100
        Re: Refer object within itself Stefan Weiss <krewecherl@gmail.com> - 2016-02-29 00:11 +0100
        Re: Refer object within itself Aleksandro <aleksandro@gmx.com> - 2016-02-29 14:49 -0300
          Re: Refer object within itself "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-02-29 19:49 +0100
            Re: Refer object within itself Aleksandro <aleksandro@gmx.com> - 2016-03-01 10:48 -0300
              Re: Refer object within itself "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-03-01 17:22 +0100
                Re: Refer object within itself Aleksandro <aleksandro@gmx.com> - 2016-03-01 15:07 -0300
                Re: Refer object within itself "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-03-01 20:26 +0100
                Re: Refer object within itself Aleksandro <aleksandro@gmx.com> - 2016-03-04 21:53 -0300
                Re: Refer object within itself "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-03-05 14:22 +0100
                Re: Refer object within itself Scott Sauyet <scott.sauyet@gmail.com> - 2016-03-05 10:17 -0800
                Re: Refer object within itself "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-03-06 11:59 +0100
                Re: Refer object within itself Ram Tobolski <ramtob@gmail.com> - 2016-03-06 10:48 -0800
                Re: Refer object within itself Scott Sauyet <scott.sauyet@gmail.com> - 2016-03-06 19:07 -0800
                Re: Refer object within itself "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-03-07 10:44 +0100
                Re: Refer object within itself Aleksandro <aleksandro@gmx.com> - 2016-03-07 12:54 -0300
                Re: Refer object within itself "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-03-07 17:59 +0100
                Re: Refer object within itself Scott Sauyet <scott.sauyet@gmail.com> - 2016-03-07 13:44 -0800
                Re: Refer object within itself "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-03-07 22:59 +0100
                Re: Refer object within itself Scott Sauyet <scott.sauyet@gmail.com> - 2016-03-07 17:00 -0800
                Re: Refer object within itself "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-03-08 10:24 +0100
                Re: Refer object within itself Scott Sauyet <scott.sauyet@gmail.com> - 2016-03-08 13:03 -0800

csiph-web