title: Custom Class Operator wrapping to v8 Engine Javascript
body: <p>Hello I am using the Google's v8 JavaScript engine and I have a straight forward question in regards to doing this in the C++ environment (NOT JS Environment).</p>
  
  <p>What I am trying to do:</p>
  
  <p>I am trying to create an object that acts like a Vector in a game environment, in this case it has a parameter of 3 floating points.</p>
  
  <p>in C++ this function has operator+ and so I can do something like...</p>
  
  <p>Example 1: (C++)</p>
  
  <pre><code>Vector vector(5,5,5);
  Vector vector2(10,10,10);
  
  Vector final = vector + vector2;
  </code></pre>
  
  <p>Which will result become 15,15,15  of course...</p>
  
  <p>Now the biggest question is how can I make it so that when I execute in JavaScript and expose Vector as the same exact object above and have</p>
  
  <p>Example 2: (JS)</p>
  
  <pre><code>var l = new Vector(5,5,5);
  var r = new Vector(10,10,10);
  
  var final = l + r;
  </code></pre>
  
  <p>in JavaScript this would typically execute the valueOf, and I could perform a similar concept of doing "Fake Operator" aka using this article</p>
  
  <p><a href="http://www.2ality.com/2011/12/fake-operator-overloading.html" rel="nofollow">http://www.2ality.com/2011/12/fake-operator-overloading.html</a></p>
  
  <p>The biggest question is how would I go about this?</p>
  
  <p>I am thinking of creating an Add function so that I can wrap the left + right in C++ then have a function calling it vector.add(15,15,15) or vector.add(right);  and will also have Vector.add(left, right); in "JS" environment though</p>
  
  <p>Now what I want to be able to do is doing the Example 2 which is JavaScript.  So when I do l + r; it will invoke the method in C++ internally calling the Add method.</p>
  
  <p>Any idea how to do this?</p>