In short: ObjectTemplate gives you JS objects without a dedicated constructor function and prototype. They use Object[.prototype]. Since you can still attach property handlers, they can be useful. FunctionTemplates give you the additional benefit that they provide a constructor function for use from JS code and JS code can add methods to the prototype.
To study a working example that shows what you need to do for your case, including JS->native reference management, check out http://github.com/ry/node/blob/master/src/node_object_wrap.h http://github.com/ry/node/blob/master/src/node_buffer.{h,cc} Matthias On Wed, Jul 7, 2010 at 9:52 PM, christy <[email protected]> wrote: > I'm confused how to use these two template. I've looked at two > examples where there seems to be contradictory information. I want to > create to expose an object from C++ to Javascript but the user should > be able in Javascript to construct the object and to extend the object > in Javascript. > > In one example the guidance is to use two FunctionTemplates: one to > represent the object and the other to represent the constructor. In > another example the ObjectTemplate::SetCallAsFunctionHandler method is > used to handle object construction. However the PrototypeTemplate is > a member of the FuncitonTemplate. It would seem to me that > ObjectTemplate should be a derive class of FunctionTemplate but I'm > really confused as which one should be used to expose C++ object to > Javascript. > > Can someone provide some guidance and provide an example. Also if you > use a code snippet please explain the object construction. I've seen > snippet where variable are introduced without any prior reference and > that severely confused me since I couldn't see how the variable was > constructed. > > Thanks in advance > christy > > -- > v8-users mailing list > [email protected] > http://groups.google.com/group/v8-users -- v8-users mailing list [email protected] http://groups.google.com/group/v8-users
