Path: csiph.com!weretis.net!feeder4.news.weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.javascript Subject: Re: Refer object within itself Date: Fri, 26 Feb 2016 19:25:02 +0100 Organization: PointedEars Software (PES) Lines: 31 Message-ID: <50246494.NvcPNDuDiy@PointedEars.de> References: <76ydnVazm-uPoU3LnZ2dnUU7-TGdnZ2d@westnet.com.au> Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Trace: solani.org 1456511103 11263 eJwFwQkBwDAIA0BLpRDSyeH1L2F3UBcvmsMNi43jk1dfiswhpD51osPizTWNy1zoNoNFZf8UFBD8 (26 Feb 2016 18:25:03 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Fri, 26 Feb 2016 18:25:03 +0000 (UTC) User-Agent: KNode/4.14.2 X-User-ID: eJwNxskBwDAIA7CVuGzIOC2E/Udo9RKcys4gGFisugyk5ohuGozXI1tub9WDaxF6CvlPpyzL9Y22886wN5MfJfgUhA== Cancel-Lock: sha1:jzl17PaS8p/HKPhtOzDMnJeD8+I= X-NNTP-Posting-Host: eJwFwYEBwDAEBMCV8oJnnKD2H6F3dh3eVDdXW9vIb3Am9jygR6NE6N46XbxGJiPrRAIiVu8HFrYQeg== Xref: csiph.com comp.lang.javascript:29710 Christoph M. Becker wrote: > Andrew Poulos wrote: >> 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); No, that is not necessary, and maybe also not equivalent to what was originally intended. -- PointedEars FAQ: | SVN: Twitter: @PointedEars2 | ES Matrix: Please do not cc me. / Bitte keine Kopien per E-Mail.