日期已过,Temporal 正在崛起
Time makes fools of us all, and JavaScript is no slouch in that department either. Honestly, I’ve never minded the latter much — in fact, if you’ve taken JavaScript for Everyone or tuned into the newsletter, you already know that I largely enjoy JavaScript’s little quirks, believe it or not.
时间让我们所有人都变得愚蠢,而 JavaScript 在这方面也不逊色。老实说,我从来不太介意后者——事实上,如果你参加过 JavaScript for Everyone 或者关注过 新闻通讯,你已经知道我在很大程度上 享受 JavaScript 的小怪癖,信不信由你。
I like when you can see the seams; I like how, for as formal and iron-clad as the ES-262 specification might seem, you can still see all the good and bad decisions made by the hundreds of people who’ve been building the language in mid-flight, if you know where to look. JavaScript has character. Sure, it doesn’t necessarily do everything exactly the way one might expect, but y’know, if you ask me, JavaScript has a real charm once you get to know it!
我喜欢当你能看到缝隙时;我喜欢尽管 ES-262 规范看起来如此正式和严谨,但如果你知道在哪里寻找,你仍然可以看到数百个在飞行中构建语言的人所做的所有好的和坏的决定。JavaScript 有个性。当然,它不一定以人们期望的确切方式做所有事情,但你知道,如果你问我,JavaScript 一旦你了解它,就真的很有魅力!
There’s one part of the language where that immediately falls apart for me, though.
不过,语言中有一个部分让我立刻感到不适。
console.log( new Date(2026, 1, 1) );
console.log( new Date(2026, 1, 1) );
The Date constructor.
Date 构造函数。
console.log( new Date( "49" ) ); console.log( new Date( "99" ) ); console.log( new Date( "100" ) );
console.log( new Date( "49" ) ); console.log( new Date( "99" ) ); console.log( new Date( "100" ) );
I dislike Date immensely.
我非常 Date 厌恶。
console.log( new Date( "2026/1/2" ) ); console.log( new Date( "2026/02/2" ) ); console.log( new Date( "2026-02-2" ) ); console.log( new Date('2026/01/02') ); console.log( new Date('2026-01-02') );
console.log( new Date( "2026/1/2" ) ); console.log( new Date( "2026/02/2" ) ); console.log( new Date( "2026-02-2" ) ); console.log( new Date('2026/01/02') ); console.log( new Date('2026-01-02') );
Date sucks. It was hastily and shamelessly copied off of Java’s homework in the car on the way to school and it got all the same answers wrong, righ...