I just found a possible solution to this problem. I feel it's a bit
hack-ish, but it works, so I'm not really complaining.
The trick is to create an ObjectTemplate with the appropriate getters
or properties, and then do:
funcTemplate->Set(v8::String::New("__proto__"),objTemplate);

I honestly don't know how I couldn't have thought of that before,
guess I was too caught up in reading all the definitions and
implementation of FunctionTemplate to notice a solution this trivial.

On Jul 20, 7:00 pm, TB <[email protected]> wrote:
> Hi,
>
> I'm trying to make a function-template that apart from having some
> default functions or values on new instances and the prototype also
> has some default properties (getters, to be more specific) on the
> actual function object.
> Something like the following Javascript example:
>
> function SillyString(str) {
>   this.str=str;
>   return this;}
>
> SillyString.prototype.silly=function() {
> print("Silly"+this.str);}
>
> //This is the part that I can't find out:
> SillyString.__defineGetter__("default",function() { return new
> SillyString("String"); });
> //Usage example
> var y=new SillyString("HelloWorld"); //<-- this should be possible
> var y=SillyString.default; //<-- Should return the equivalent of new
> SillyString("String");
>
> Would anyone have any idea how to go about doing this ? I've tried
> using just an ObjectTemplate with a SetCallAsFunctionHandler, but that
> throws a type error when used with "new".
>
> Thanks,
> TB
--~--~---------~--~----~------------~-------~--~----~
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to