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
Why does Chrome Dev Tool show a dates __proto__ as Invalid Date?
提问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 toString
value of the prototype
object of the Date
constructor function.
这只是构造函数toString
的prototype
对象的值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 实例的原型没有定义的值。只有实例才有值。在实例化它时定义它。