what is the difference between new(Date) and new Date()?

懵懂的女人 提交于 2019-12-23 08:30:12

问题


In javascript, the typical way to new up an object is by doing it like this: new Date(). But you can also do this: new (Date). What is the difference and advantages of doing it the latter way?


回答1:


There is no difference.

The new operator takes a function reference.
Like any other operator, the operand can have parentheses.

The () after a new expression with no arguments are optional.

However, if you have more a complicated expression inside the parentheses, they can change precedence ordering, such as in this answer.




回答2:


I believe the latter way is identical to the first way. I think it will be interpreted as new Date since there is nothing to evaluate in the parentheses. Note that new Date is equivalent to new Date().



来源:https://stackoverflow.com/questions/8236058/what-is-the-difference-between-newdate-and-new-date

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!