简体   繁体   English

JS Date对象未定义

[英]JS Date object undefined

I've written a function in JavaScript that returns, each time you invoke it, a new instance of this Object. 我已经用JavaScript编写了一个函数,该函数在每次调用它时都会返回此Object的新实例。 Among its properties, this instance has a date property, which is being initialized when 'starting' this object (it's a server object): 在其属性中,此实例具有date属性,当“启动”此对象(它是服务器对象)时,该属性将被初始化:

instance.startedTime = new Date();

Later on, I have a function that returns this server instance' properties. 稍后,我有一个函数返回该服务器实例的属性。 When calling it, it returns 'undefined' for the instance.startedTime property. 调用它时,它为instance.startedTime属性返回“未定义”。
Why is that, and how can I pass the date properly? 为什么会这样,如何正确传递日期?

为什么不只节省时间呢?

instance.startedTime = (new Date).getTime();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM