Message from discussion
FunctionTemplate with accessors
Received: by 10.150.96.13 with SMTP id t13mr3959954ybb.19.1248112339152;
Mon, 20 Jul 2009 10:52:19 -0700 (PDT)
Return-Path: <ernst.matth...@gmail.com>
Received: from mail-yx0-f172.google.com (mail-yx0-f172.google.com [209.85.210.172])
by gmr-mx.google.com with ESMTP id 14si770370gxk.3.2009.07.20.10.52.18;
Mon, 20 Jul 2009 10:52:18 -0700 (PDT)
Received-SPF: pass (google.com: domain of ernst.matth...@gmail.com designates 209.85.210.172 as permitted sender) client-ip=209.85.210.172;
Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of ernst.matth...@gmail.com designates 209.85.210.172 as permitted sender) smtp.mail=ernst.matth...@gmail.com; dkim=pass (test mode) header...@gmail.com
Received: by yxe2 with SMTP id 2so4396554yxe.14
for <v8-users@googlegroups.com>; Mon, 20 Jul 2009 10:52:18 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=gamma;
h=domainkey-signature:mime-version:received:in-reply-to:references
:date:message-id:subject:from:to:content-type
:content-transfer-encoding;
bh=IwTHiD96AWvpYj1i2i9/AB7Z/meXU+kOtPO50HxHai4=;
b=T9WGBQhIbTYcPYEH5BZFYQVTCC8xSh7squ2nTCdlZ/MDuX1IynDMp+LRvJLIALrYxw
M1hgh2Ypj6qJjqwQ2I3IOrCLCfrswvI6ZLU8dnhUBK3TuKM+XavANKObplJ9fvdjQcNA
LRBAxxi7T+lfsrkbtiHKj0gawCAZj1D3dl7ic=
DomainKey-Signature: a=rsa-sha1; c=nofws;
d=gmail.com; s=gamma;
h=mime-version:in-reply-to:references:date:message-id:subject:from:to
:content-type:content-transfer-encoding;
b=oUJOX3mLU0hutgkOqfML0Ewhm6fkLrswNaXBtCI76DeblfRPy8xSkRovXXx/TXhiIX
4a66vwluiqOj18a0t5tuSAPB5XO7zYB8fUHPH7iKjPnqvMXl/sM+0kupyE3uoTTP7nhl
wBxYLapu8x5XjSVG9ZQcLKCjRxLgDyR5vaOw4=
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Received: by 10.151.13.9 with SMTP id q9mr7311424ybi.18.1248112337996; Mon, 20
Jul 2009 10:52:17 -0700 (PDT)
In-Reply-To: <de7b77be-9837-474c-942e-6d6b3a9eca66@b15g2000yqd.googlegroups.com>
References: <9251a4e1-f254-4794-829f-65492b699...@q11g2000yqi.googlegroups.com>
<de7b77be-9837-474c-942e-6d6b3a9ec...@b15g2000yqd.googlegroups.com>
Date: Mon, 20 Jul 2009 19:52:17 +0200
Message-ID: <22ec15240907201052r761bfa0t55eda52c2390f...@mail.gmail.com>
Subject: Re: [v8-users] Re: FunctionTemplate with accessors
From: Matthias Ernst <ernst.matth...@gmail.com>
To: v8-users@googlegroups.com
On Mon, Jul 20, 2009 at 7:41 PM, TB<thebl...@gmail.com> 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);
You should just as well be able to Set these properties on the
funcTemplate instead.
Or even on the funcTemplate->GetFunction() object, since there is only
gonna be one object created from that template anyway.
> 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=A0pm, TB <thebl...@gmail.com> 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) {
>> =A0 this.str=3Dstr;
>> =A0 return this;}
>>
>> SillyString.prototype.silly=3Dfunction() {
>> 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=3Dnew SillyString("HelloWorld"); //<-- this should be possible
>> var y=3DSillyString.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
> >
>