Check whether function result value is used
<p>I was wondering whether it is possible to check whether a function is called in such a way that its return value is stored in a variable, or that it is called 'standalone'.</p>

<p>In the first case, the function should indeed return something, but otherwise it should save the value(s) to the current instance of my object.</p>

<p>To be specific, I have a <code>Vector3D</code> as follows:</p>

<pre><code>function Vector3D(x, y, z) {
  this.x = parseNumber(x);
  this.y = parseNumber(y);
  this.z = parseNumber(z);
}

Vector3D.prototype.add = function(that) {
  return new Vector3D(
    this.x + that.x,
    this.y + that.y,
    this.z + that.z
  );
};
</code></pre>

<p>As can be seen, the <code>add</code> function returns something based on the object instance itself and on another instance. As it is now, the function must be called in a way like this:</p>

<pre><code>var addedVector = vect1.add(vect2);
</code></pre>

<p>However, if I were to call it like this:</p>

<pre><code>vect1.add(vect2);
</code></pre>

<p>it should not return anything (that's quite useless), but instead store the return coordinates (<code>x</code>, <code>y</code> and <code>z</code>) in the variables of vect1. So vect1 should become what is called addedVector in the other line of code.</p>

<p>To accomplish this, I guess I'm going to need to know whether the function is called alone or that its return value is stored.</p>

<p>Is there any way to accomplish this?</p>
