Closed Bug 779326 Opened 12 years ago Closed 12 years ago

Add Date.isDate() helper

Categories

(Core :: JavaScript Engine, defect)

Other Branch
defect
Not set
normal

Tracking

()

RESOLVED WONTFIX

People

(Reporter: philikon, Assigned: philikon)

Details

Because

  Object.prototype.toString.call(maybeADate) == "[object Date]"

is ugly (cf. arrays) and

  maybeADate instaceof Date

is problematic (just like with arrays) when you're working with objects from different JS scopes (e.g. chrome JS working with objects handed over from content.)
I'm happy to give this a stab if people think this is a good idea. (Though my bets are still on it being a dupe somehow, although I did my best at finding existing bugs.)
Assignee: general → philipp
Wouldn't that have to be a method on all objects then?
(In reply to Benjamin Peterson from comment #2)
> Wouldn't that have to be a method on all objects then?

What do you mean? I'm proposing adding Date.isDate(), not Date.prototype.isDate(). Or are worried about setting a precedent and we'll have to add Foobar.isFoobar() for all built-in types?
Ah, it's on the constructor. There is precedent for that with the Array constructor. On the other hand, I think Array is the exception in having this attribute.

More generally, it's a shame to add new language features that people will depend on and we'll have to support forever just to work around our own content/chrome issues.
(In reply to Benjamin Peterson from comment #4)
> Ah, it's on the constructor. There is precedent for that with the Array
> constructor. On the other hand, I think Array is the exception in having
> this attribute.

Sure, but there aren't that many built-in types to begin with. On top of that, there aren't many types where you have to resort to Object.prototype.toString.call. I think those are 

> More generally, it's a shame to add new language features that people will
> depend on and we'll have to support forever just to work around our own
> content/chrome issues.

That's fair, I suppose.
Not that I'm necessarily opposed to this, mind, but we take features after they've passed through (or at least substantially into) the standards process, via the es-discuss mailing list:

https://mail.mozilla.org/listinfo/es-discuss

Feel free to propose there, and if the idea gets uptake (I really don't know why only Array.isArray was added, and not *.is* for all the builtin kinds of objects), reopen at that point.  I imagine this has been discussed at some point, but I don't follow discussion enough to say that it has, or to link to any such discussion, alas.
Status: NEW → RESOLVED
Closed: 12 years ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.