The reason why you use args.This() instead of creating an empty Value<Object> and appending keys to that is partially due to the way the "new" operator works in JavaScript when called with a function and operating in accordance with that when "faking" JS object creation via C++ functions. Roughly speaking, it does the following (in order):
1) First creates an empty object 2) Sets the new objects hidden "prototype" field to the function's "prototype" member, if there is one. (interpret this loosely, changes slightly from interpreter to interpreter, but essentially this is what happens ) 3) Sets "this" to the empty object, and then calls the function body (making any changes to "this" happen to the empty object) The interesting part comes in when you consider the way in which v8 implements callbacks: you want the callback function to behave like "Normal JS", but v8 function callbacks don't work in quite way you might expect. You might expect, for instance, that "Set" would overwrite any function present within the object, and that overriding a function declared with "Set" would simply get rid of the callback. >From what I believe, the first is true, but I know for sure the second is not. If you overwrite a function within JS, the overriding function will be called *before* your function callback, but both will be called. However, your C++ callback will be the function that actually "returns" a value. So in order to preserve any changes made to "this" during the callback, you extend args.This(), and do not simply create a new Object (unless this is what you desire). Hope that helps, Stew On Mon, Apr 23, 2012 at 9:37 PM, Ben Noordhuis <i...@bnoordhuis.nl> wrote: > On Tue, Apr 24, 2012 at 02:54, Ryan Cole <r...@rycole.com> wrote: > > I'm wrapping a C++ object and then appending some properties. I'm calling > > Wrap(), and then Set()'ing the properties directly onto args.This(). This > > does not look or feel right to me, so I'm inclined to think I'm doing it > > wrong. I'm so new to this that none of the examples are standing out to > me > > as the proper way of doing this. > > > > Can someone please take a peek at the highlighted lines of my code and > give > > me a few pointers? Namely, am I doing this incorrectly? > > > > > https://github.com/ryancole/node-hdf5/blob/master/src/node_h5file.cc#L67-74 > > There's nothing really wrong with that approach. If the properties are > subject to change, you could use ObjectTemplate::SetAccessor() > instead. > > -- > Job Board: http://jobs.nodejs.org/ > Posting guidelines: > https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines > You received this message because you are subscribed to the Google > Groups "nodejs" group. > To post to this group, send email to nodejs@googlegroups.com > To unsubscribe from this group, send email to > nodejs+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/nodejs?hl=en?hl=en > -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to nodejs@googlegroups.com To unsubscribe from this group, send email to nodejs+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en