Is it possible to have a method act like a property in a javascript class?
<p>Take the following piece of javascript that is trying to implement a class:</p>

<pre><code>function aClass(){
  this.prop1 = this.getProp1();
}

aClass.prototype.getProp1 = function(){
  // do some stuff
  return result;
}
</code></pre>

<p>I can then use it like so:</p>

<pre><code>var obj = new aClass();
alert(obj.prop1);
</code></pre>

<p>What I now want to do is this:</p>

<pre><code>obj.prop1 = "some value";
</code></pre>

<p>This, of course overrides prop1, and I can no longer retrieve the generated result from the getProp1 function.</p>

<p>So in short, is it possible to create a property that allows read and write, but instead calls a function in both cases for, say, validation purposes?</p>

<p>I'm happy for a completely different approach to what I have here as long as I get the desired effect.</p>

<p>It needs to work with older browsers.</p>
