Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我试图了解在以下返回语句中 Date 构造函数周围额外括号的使用:
if (!Date.now) { Date.now = function now() { return +(new Date); // <-- ??? }; }
资源
是否存在不能省略这些括号的极端情况?谢谢!
括号不是必需的。
return +new Date;
也可以。需要括号来帮助理解表达式,但它们也可以更改评估的默认优先顺序。此顺序在 ECMAScript 的词汇语法部分中定义。
http://www.ecma-international.org/ecma-262/5.1/#sec-A.1