Frozen Date objects?

Allen Wirfs-Brock allen at
Mon Jul 22 10:28:50 PDT 2013

On Jul 22, 2013, at 9:42 AM, Jonas Sicking wrote:

> On Mon, Jul 22, 2013 at 7:42 AM, Allen Wirfs-Brock
> <allen at> wrote:
>> 3.  Is it ever appropriate for a DOM API to accept and retain a reference to
>> a Date object?
> We could even generalize it to:
> 3. Is it ever appropriate for a DOM API to accept a reference to a Date object.
> Even if we just take a snapshot of the value returned by .getTime()
> and retain that snapshot, is that really beneficial to taking a
> numeric timestamp?
> The feedback in this thread seems to indicate "no" on all three?

However, just like you you guys trying to define DOM APIs, many JavaScript programmers will not be aware of these subtleties and expect to be able to use Date objects with these APIs.  I would suggest, the following conventions:

1)  APIs should accept Date objects as inputs, but when doing do so they should only retain and use the timevalue wrapped by the date object.
2) APIs may return Date objects but they should always be newly created instances and never retain references to them.  An API client might mutate such returned Date objects but that's really the clients business  and it will have no impact upon the DOM.

In addition, for APIs that take "dates" as input might consider accepting both Date objects and Numbers that are interpreted as timevalues.  That should probably be a design decision that is consistently applied to all DOM APIS.


More information about the es-discuss mailing list