89

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);
Shane Courtrille
  • 13,960
  • 22
  • 76
  • 113

3 Answers3

87

"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.
  • 49
    You are close, but the "why" part is still missing, the reason is that the [`Date.prototype`](http://es5.github.com/#x15.9.5) object is a *Date object by itself* but its `[[PrimitiveValue]]` internal property is `NaN` (this internal property on date objects stores the [time value](http://es5.github.com/#x15.9.1.1)), so it doesn't represent actually a valid date. `Date.prototype` is an object similar to `new Date(NaN)`... – Christian C. Salvadó Mar 15 '12 at 18:05
  • @CMS: Makes sense. That's good info. Feel free to add it to the answer if you'd like. –  Mar 15 '12 at 18:08
  • 4
    so basically, there is no error and Chrome is just reflecting the toString() which doesn't show the true value – Kat Lim Ruiz Mar 19 '14 at 18:45
  • 3
    Plus one for the love of turtles – Guy Sep 27 '15 at 01:33
2

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.

Community
  • 1
  • 1
Ben Sewards
  • 2,571
  • 2
  • 25
  • 43
0

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

dmvianna
  • 15,088
  • 18
  • 77
  • 106