title: How can I access a dynamic variable created in C++ from Javascript? (bound via V8)
body: <p>Google was nice enough to explain how to <a href="http://code.google.com/apis/v8/embed.html#dynamic" rel="nofollow noreferrer">wrap C++ class methods with accessors that can be used from the V8 Javascript engine</a>.</p>
  
  <p>However, they don't mention how to determine the name of the JavaScript object that will have these accessor properties available.</p>
  
  <p><strong>How do I tell V8 Javascript what the name of the C++ class instance (from the sample) is? Or if it already has a name, what is it?</strong></p>
  
  <p>These two lines set up the accessors:</p>
  
  <pre><code>point_templ.SetAccessor(String::New("x"), GetPointX, SetPointX);
  point_templ.SetAccessor(String::New("y"), GetPointY, SetPointY);
  </code></pre>
  
  <p>I assume they can be used like this from JavaScript:</p>
  
  <pre><code>someObject.x = someObject.y * 2;
  </code></pre>
  
  <p>How do I determine what "<code>someObject</code>" is?</p>
  
  <p>I feel there is some code missing that finishes linking the C++ code with the V8 Javascript wrapper.</p>
  
  <p>For example, in the sample code to <a href="http://code.google.com/apis/v8/embed.html#static_global" rel="nofollow noreferrer">access static global variables</a> there was a line that explicitly exposed the accessor functions to V8 JavaScript:</p>
  
  <pre><code>Handle&lt;ObjectTemplate&gt; global_templ = ObjectTemplate::New();
  global_templ-&gt;SetAccessor(String::New("x"), XGetter, XSetter);
  global_templ-&gt;SetAccessor(String::New("y"), YGetter, YSetter);
  Persistent&lt;Context&gt; context = Context::New(NULL, global_templ)
  </code></pre>