javascript 为什么 Chrome Dev Tool 将日期 __proto__ 显示为无效日期?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9725299/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 07:37:27  来源:igfitidea点击:

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

javascriptgoogle-chrome-devtools

提问by Shane Courtrille

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..

我知道__proto__不推荐使用(或不是标准的一部分)等等,但我仍然很好奇当我查看__proto__..

var myDate = new Date(1331869050000);

采纳答案by Shane Courtrille

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

“我仍然很好奇它说无效日期是什么意思”

That's simply the toStringvalue of the prototypeobject of the Dateconstructor function.

这只是构造函数toStringprototype对象的值Date



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.

有点离题,但__proto__在 ECMAScript 下一个版本(代号 Harmony)的当前工作草案中。

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

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

  • Added section B.3.1 with specifies __proto__feature.
  • 添加了 B.3.1 节并指定了__proto__功能。

回答by Ben Sewards

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

考虑到您创建了一个新的 Date 对象,我不会担心。原因是,如果您尝试此代码:

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.

这将确定您正在继承 Date 对象方法,并且实际上已定义 Date。

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

如果你想进一步调查,看看这篇文章。

回答by dmvianna

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

Date 实例的原型没有定义的值。只有实例才有值。在实例化它时定义它。