The "prototype" property is the __proto__ property for the objects
created with that function as constructor, not the __proto__ property
of that function itself.
e.g.:
function f() { return this; };
var a=new f();
f.prototype.test="Value";Would set a.test but not f.test as intended. On Jul 20, 7:51 pm, Dean McNamee <[email protected]> wrote: > /** > * A PrototypeTemplate is the template used to create the prototype object > * of the function created by this template. > */ > Local<ObjectTemplate> PrototypeTemplate(); > > > > On Mon, Jul 20, 2009 at 7:41 PM, TB<[email protected]> wrote: > > > 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 -~----------~----~----~----~------~----~------~--~---
