Thanks Omkar. This is not exactly what I've been looking for, but I can use this approach as a workaround.
On 4 Jan., 06:27, Omkar Kulkarni <[email protected]> wrote: > In your C++ code, args.This() points to 'myextension' and not 'a', > which is why it is unable to access the property. > You will have to pass a reference to 'a' and not a reference to > 'callback' in order to get the right context. > > Your C++ code should look something like this -- > > Handle<Value> MyExtension::Add(const Arguments& args) > { > HandleScope scope; > Handle<Object> object = args[0].As<Object>(); > Handle<Function> func = > object->Get(String::New("callback")).As<Function>(); > > func->Call(object, 0, NULL); > return scope.Close(Undefined()); > > } > > And in Javascript -- > > myextension.add(a); > > Hope that helps! > > - Omkar > > On Jan 3, 10:37 am, Sebastian <[email protected]> wrote: > > > > > > > > > Hello together, > > > I want to call a function which is a member of a class instance. > > > Consider the following Javascript code. > > function MyClass(name) > > { > > this.name = name; > > this.callback = function () { console.log("My name is " + > > this.name"); } > > > } > > > var a = new MyClass("MyCallbackClass"); > > > myextension.add(a.callback); > > > In my C++ part: > > Handle<Value> MyExtension::Add(const Arguments& args) > > { > > HandleScope scope; > > Local<Function> func = > > Local<Function>::New(args[0].As<Function>()); > > func->Call(args.This(), 0, NULL); > > return scope.Close(Undefined()); > > > } > > > When executing the code, the output is: "My name is Undefined" instead > > of "My name is MyCallbackClass. I guess this happens because I'm > > passing the wrong first argument (recv) to func->Call(), but how do I > > get the correct "this" to pass it to function call? > > > Thanks in advance. > > > Cheers, > > Sebastian -- v8-users mailing list [email protected] http://groups.google.com/group/v8-users
