Why does Chrome Dev Tool show a dates __proto__ as Invalid Date?

JavascriptGoogle Chrome-Devtools

Javascript Problem Overview


I know __proto__ is deprecated (or not part of the standard) and all that but I'm still curious as to what it means when it says Invalid Date when I look at the __proto__ value of..

var myDate = new Date(1331869050000);

Javascript Solutions


Solution 1 - Javascript

>"I'm still curious as to what it means when it says Invalid Date"

That's simply the toString value of the prototype object of the Date constructor function.


Date.prototype.toString(); // "Invalid Date"

You can override it if you like...

Date.prototype.toString = function() { return "I like turtles." };

var myDate = new Date(1331869050000);
myDate.__proto__; // I like turtles.

A little off topic, but __proto__ is in the current working draft for the next version of ECMAScript, codename Harmony.

http://wiki.ecmascript.org/doku.php?id=harmony:specification_drafts

> - Added section B.3.1 with specifies __proto__ feature.

Solution 2 - Javascript

considering you made a new Date object, I wouldn't worry about it. The reason being, if you try this code:

var myDate = new Date(1331869050000);
alert(typeof myDate.getMonth != 'undefined')    //true

This will determine that you are inheriting the Date objects methods and that in fact, Date IS defined.

If you would like further investigation, take a look at this post.

Solution 3 - Javascript

The prototype of a Date instance has no defined value. Only the instance has a value. You define it when you instantiate it.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionShane CourtrilleView Question on Stackoverflow
Solution 1 - Javascriptuser1106925View Answer on Stackoverflow
Solution 2 - JavascriptBen SewardsView Answer on Stackoverflow
Solution 3 - JavascriptdmviannaView Answer on Stackoverflow