On Wed, Jan 5, 2011 at 4:10 PM, Stephan Beal <[email protected]> wrote:
> On Wed, Jan 5, 2011 at 2:38 PM, Matthias Ernst <[email protected]> wrote:
>>
>> you do - instead create only one or a bounded number of templates for
>> foo and use JS functions and scoping to bind different dynamic values
>> to it.
>
> @Andrey:
> i believe you could to that by associating the Function object with your
> accessor function. ObjectTemplate::SetNamedPropertyAccessor() has a 'data'
> argument to which you can pass the GetFunction()->NewInstance() value. In

Err, without "->NewInstance()". You want the function itself.

> your property handler, use Arguments::Data() to fetch that Function.
> At least i _think_ that's how the data parameter works.

Yes, that's an option. Basically you can have one generic "return
arguments.Data()" property accessor and do
SetNamedPropertyAccessor('foo', GenericDataReturningAccessor,
Function::New(foo));

Alas, you can just as well set the bound foo function as a regular JS
property of the prototype just like you do in JS:
Bar.prototype.foo = function() { ... }
=>
Handle<FunctionTemplate> bar = ...
bar->PrototypeTemplate()->Set("foo", Function::New(foo));

A Bar now understands foo().

-- 
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users

Reply via email to