Javascript :: Syntax - variable assignment
<p>Let's have the following functionality:</p>

<pre><code>function transformMatrix(a, b, c, d, e, f)
{
  this.data = [a, c, e, b, d, f, 0, 0, 1];
}

transformMatrix.prototype.inverse = function()
{
  //..
  this.data = newdata;
  return this.data;
}
</code></pre>

<p>and</p>

<pre><code>var m1 = new transformMatrix(1, 0, 0, 1, 10, 20); // translate (10, 20)
</code></pre>

<p>Now, when I call</p>

<pre><code>m1.inverse();
</code></pre>

<p>variable <code>m1</code> is changed.</p>

<p>But when I call</p>

<pre><code>var m2 = m1.inverse();
</code></pre>

<p>variable <code>m1</code> is changed and such changed is copied to variable <code>m2</code>. Great!</p>

<p>Is there a way to assign result of <code>inverse</code> to a new variable without change of the original one? </p>

<p>I can do that by:</p>

<pre><code>var m2 = m1;
m2.inverse();
</code></pre>

<p>But I would like to know, if there is some other way, without prior assignment, something like</p>

<pre><code>var m2 = {m1}.inverse(); // incorrect syntax
</code></pre>

<p>that would not change <code>m1</code>.</p>

<p>Please note that functionality of <code>inverse</code> function should not be changed.</p>

<p>Any help will be appreciated. Thank you...</p>
