Date() constructor definition

I tried to understand the semantics of Date() constructors with arguments, as defined in sections and of ECMA-262, 10th edition. The step 3 in both sections says:

  1. If NewTarget is undefined, then
    a. Let now be the Number that is the time value (UTC) identifying the current time.
    b. Return ToDateString(now).

If I understand correctly, "NewTarget is undefined" means that the constructor is being called as a function. This step seems to say that if Date() with argument(s) is called as a function, the argument(s) are ignored and current time is returned. Or, just maybe, it is an unedited copy-paste from the Date() with no arguments?

I am new to reading the ECMAScript specification, which is not particularly fool-friendly, so I thought I will ask a question before formally reporting an issue: What am I missing? is for when Date is called with 2+ arguments, is for when it's called with 1, and is for when it's called with zero.

More precisely: arguments are ignored and a string representation of the current date & time is returned.

Thanks! So is ignoring parameters the intended behavior? It seems a bit weird to me.

It's been that way since the first edition of the ECMAScript spec:

When Date is called as a function rather than as a constructor, it returns a string representing the current time(UTC). [...] The arguments are accepted but are completely ignored.

Again, it doesn’t ignore parameters; the Date function is overloaded in the spec, so the zero-parameter one only applies to a zero argument invocation.

1 Like

But this question isn't about zero-argument invocations, it's about invocations "with arguments". So the first or second overloads are relevant, and both of them ignore parameters when you invoke Date "as a function".

1 Like

Thanks a lot! This design is highly confusing. But OK, at least I have understood the specification correctly :)