W3C home > Mailing lists > Public > public-html@w3.org > September 2009

Re: Web IDL Garden Hose

From: Maciej Stachowiak <mjs@apple.com>
Date: Sun, 27 Sep 2009 16:04:31 -0700
Cc: es-discuss@mozilla.org, public-webapps@w3.org, HTML WG <public-html@w3.org>
Message-id: <825CD335-3B85-4505-8BE4-28B4184914CC@apple.com>
To: Brendan Eich <brendan@mozilla.com>

On Sep 27, 2009, at 11:14 AM, Brendan Eich wrote:

> On Sep 27, 2009, at 10:41 AM, David-Sarah Hopwood wrote:
>
>> Brendan Eich wrote:
>>> On Sep 26, 2009, at 6:08 PM, Maciej Stachowiak wrote:
>>>
>>>> This may provide a way to implement some of these behaviors in pure
>>>> ECMAScript. The current proposal does allow [[Construct]] without
>>>> [[Call]], but not [[Call]] and [[Construct]] that both exist but  
>>>> with
>>>> different behavior.
>>>
>>> Date needs the latter.
>>
>> That can already be done in ES5. As I've previously suggested:
>>
>> function Date(yearOrValue, month, date, hours, minutes, seconds,  
>> ms) {
>>   "use strict";
>>   if (this === undefined) {
>>     return TimeToString(CurrentTime());
>>   }
>>   // constructor behaviour
>>   ...
>> }
>
> Of course, a variation on "the idiom".
>
> This is similar to what many implementations do too, rather than the  
> implementation providing analogues of [[Call]] and [[Construct]]  
> internal method on a non-function Date object. It works for Boolean,  
> Number, String, and RegExp too.
>
> But it is just a bit unsightly!

Will this do the right thing if you explicitly bind Date to a "this"  
value, for example, by calling it as window.Date(), or using call,  
apply, or function.bind, or by storing Date as the property of another  
random object?

Regards,
Maciej
Received on Sunday, 27 September 2009 23:05:13 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 9 May 2012 00:16:49 GMT