Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
383 views
in Technique[技术] by (71.8m points)

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

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);
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...