return a value from object in js
<p>Assume I have a simple object in js with one private variable:</p>

<pre><code>function test(){
var value=true;
}
</code></pre>

<p>and now I want to create one instance:</p>

<pre><code>var r=new test() //I want to get r === true
</code></pre>

<p>How can I return a value from it?</p>

<p>If I write:</p>

<pre><code>function test(){
var value=true;

return value;
}
</code></pre>

<p>I have a test {} in result.</p>

<p>If I write:</p>

<pre><code>function test(){
var value=true;

return function(){ return value; } 
}
</code></pre>

<p>then I can get the value, but I must add additional parentheses:</p>

<p>var r=new test()() //r === true</p>

<p>I don't want the parentheses, so I tried to change the code to:</p>

<pre><code>function test(){
var value=true;

return (function(){ return value; } )();
}
</code></pre>

<p>But in response, again I get test {}
How to write the return statement in this situation?</p>
