.getTime()是JavaScript中新的Date()或Date()的函数吗?

沙吞

具体来说,哪个是正确的?

new Date().getTime();

或者

(new Date()).getTime();

谢谢

阿尔约姆·纽斯特罗耶夫(Artyom Neustroev)

如前所述,两者都是正确的。我想问题更多是关于new操作员的工作它的存在可以通过以下示例描述:

var constr = function() { 
   return { 
      getConstructor: function() { 
         return Date 
      } 
   }; 
};

console.log(new constr()); // Object { getConstructor: function }
console.log(new constr().getConstructor); // function () { return Date }
console.log(new constr().getConstructor()); // function Date() { [native code] }
console.log(new (constr().getConstructor())); // Wed Mar 25 2015 20:10:07 GMT+0500 (YEKT) 

因此,如果要创建由嵌套函数返回的构造函数的实例,则应考虑使用new (code that returns constructor)而不是new [code that eventually returns constructor]后者将不起作用,因为new它将选择第一个函数调用并创建一个实例。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

python函数返回javascript date.getTime()

Java Date getTime函数返回负值

React中新的Date()。getFullYear()

新的Date()。getTime()在JavaScript中显示NaN

JavaScript Date.getTime函数未返回正确的值,或者我做错了

javascript中的Date(d.getTime())和new Date(d.getTime())有什么区别?

你可以从Date()。getTime获取年/月/日吗

date.getTime不是一个函数

解释javascript Date()函数

JavaScript GetTime 函数

javascript date.valueOf()和java date.getTime()之间的区别

对java.util.Date中的getTime和getTimeImpl方法感到困惑吗?

Date.now()、new Date().getTime() 和 +new Date 的区别

TypeError:date.getHours不是函数吗?

javascript-如何以毫秒格式获取与javascript中的新Date()。getTime()类似的UTC日期?

什么更快?System.currentTimeMillis()或Date()。getTime()?

Date.getTime()不包括时间?

在date.gettime()中获得负值

Date.parse()和.getTime()之间的区别

date.getTime()比System.getCurrentTimeMillis()短

转换Javascript new Date()。getTime(); 放入R识别的时间戳记(最好使用lubridate)

Javascript 不支持 64 位整数,为什么 new Date().getTime() 返回 41 位数字?

来自 <input type="date" /> 的 Html5 javascript gettime(),奇怪的工作

为什么+ new Date()返回与new Date()。getTime()相同的内容?

Date date = calendar.getTime() 返回过去的日期

BigQuery 的 PARSE_DATE 函数可以处理 ISOWEEK 吗?

moment js函数和javascript date函数之间的区别

Lua 中的 socket.gettime 函数需要联网吗?

相当于新的Date()的。的getTime()在Java中8