【问题标题】:Running variable is NaN, but debugging variable isn't NaN. Why?运行变量是 NaN,但调试变量不是 NaN。为什么?
【发布时间】:2018-07-25 17:04:17
【问题描述】:

为什么 eventFace.order 是 NaN 运行而 eventFace.order 不是 NaN 调试? 错误:

let update = true;
const farAway = new Date(GetToday(500)).getTime();

for (const eventFace of facebookEvents) {
  update = true;
  for (const eventFire of firebaseEvents) {
     if (eventFace.id === eventFire.id) {
       update = false;
     }
  }

  if (update) {
    const eventDate = new Date(FormatDate(eventFace.start_time)).getTime();
    eventFace.order = farAway - eventDate;
    firebase.database().ref().child('events').push(eventFace);
  }
}

【问题讨论】:

  • 您查看过所有的 eventFace 对象吗?似乎这段代码new Date(FormatDate(eventFace.start_time)).getTime() 正在生成NaN,如果这是正确的,那么这就是您在eventFace.order 中收到NaN 的原因

标签: javascript reactjs firebase react-native redux-thunk


【解决方案1】:

使用 React Native 时,您将在两种环境中运行 JavaScript 代码:

在 iOS 模拟器和设备、Android 模拟器和设备上,React Native 使用 JavaScriptCore,它是支持 Safari 的 JavaScript 引擎。在 iOS 上,JSC 不使用 JIT,因为 iOS 应用程序中没有可写的可执行内存

当使用 Chrome 调试时,它会在 Chrome 本身中运行所有 JavaScript 代码,并通过 WebSocket 与本机代码进行通信。所以你使用的是 V8。所以,最好使用 momentJS 之类的替代方法,而不是 Date object.Like

moment(FormatDate(eventFace.start_time), "MM-DD-YYYY Z").valueOf()

注意:FormatDate 现在应该将日期转换为时刻格式“MM-DD-YYYY Z”

您可以查看以下文章了解更多信息。

https://medium.com/@suyogkrazz/you-should-not-always-rely-on-remote-debugging-react-native-787a850c7ad8

【讨论】:

    猜你喜欢
    • 2020-06-17
    • 1970-01-01
    • 2018-05-30
    • 1970-01-01
    • 2012-04-22
    • 2014-08-07
    • 2014-04-14
    • 2021-09-19
    • 2013-12-17
    相关资源
    最近更新 更多