Is it possible to "return a getter" in javascript
<p>I want to do something like this:</p>

<pre><code>function x(){
    var o = {};
    o.__defineGetter__('y', function(){
        return new Date();
    });

    return o.y;
}

var z = x();
console.log(z);
//Wait 1 second
console.log(z); //Date should be one second past the last printing
</code></pre>

<p>Of course, this doesn't work because o.y is evaluated when it is returned. I'm looking for a way to return a variable that acts as a getter. The following example gives me hope that something like this could be possible:</p>

<pre><code>function x(context){
    //Bind the getter to the passed in scope
    context.__defineGetter__('y', function(){
        return new Date();
    });
}

x(this);
console.log(y);
//Wait 1 second
console.log(y); //Date is one second past last printing
</code></pre>

<p>Has anyone ever tried to do something like this? </p>

<p>Yes, I'm familiar with other ways to model similar behavior using different syntax. I just want this particular syntax to work for a special scenario.</p>

<p>Thanks,</p>

<p>Chris</p>
