How to refer a field inside a JS object definition?
<p>Well, the question may be not good formulated, but I'll try to get it more clear by example:</p>

<pre><code>var test = {
            x1 : 10,
            x2 : 20,
            x3 : x1 + 5,
            x4 : x2 + 5,
        }
</code></pre>

<p>What I need, is refer to "x1" or "x2" field, which was previously declared. But, if I wrote like in example, JS says, that "x1 is not defined".<br>
My second try was:</p>

<pre><code>var test = {
            x1 : 10,
            x2 : 20,
            x3 : this.x1 + 5,
            x4 : this.x2 + 5,
        }
</code></pre>

<p>But "x3" and "x4" become "NaN", because "this.x1", and "this.x2" is "undefined".<br>
I even tried:</p>

<pre><code>var test = {
            x1 : 10,
            x2 : 20,
            x3 : test.x1,
            x4 : test.x2,
        }
</code></pre>

<p>But get "test is undefined".
So, how can i refer, to "x1" or "x2"?<br>
P.S. I know, that I can write something like:</p>

<pre><code>var test2 = new (function(){
        this.x1 = 10;
        this.x2 = 20;
        this.x3 = this.x1 + 5;
        this.x4 = this.x2 + 5;
    })();
</code></pre>

<p>And it will work just fine, but I really need a JSON-like object definition.</p>

<p>Update: I forgot that this description of object is called a "literal". Because of that I couldn't find existing questions about this theme. However, now I've read similar questions and answers for them, and have not found answer, that solve my problem.<br>
In fact I need to remain in literals notation, because I am developing a "configuration file format", that must have a declarative syntax (and parser for this format of course, that will execute some algorithm according to this configuration file). And this configuration file must be understandable and editable by people, who don't understand JS. For them it's not a script, or object, but just a JSON with specified structure. So I can't use some init function in the end.<br>
Even getters will add too many complexity. It may sound funny, but yes, it's too complex. It will add keywords "get", and "return", and also round brackets and semicolon punctuation. When JSON syntax have only two type of brackets and two type of punctuation: colon and comma. So the complexity almost doubled with getters or functions, even if they would be consists of only one string.<br>
For now I'm leaning towards option, just to add the "id" field, and referenced by it. But maybe someone could offer a better solution.  </p>

<p>P.S.  I dont have any option other than use some valid JS for this configuration file, because my application would not have any server side. Only local JS and HTML file, and only standard browser for run them, so no file access. Because of that configuration file will be provided to application in form of JS file.</p>