英文:
Getting this {"_h": 0, "_i": 0, "_j": null, "_k": null} instead of a Number in React Native
问题
我正在尝试创建一个函数,该函数返回服务器时间戳字段值与即时客户端时间戳之间的时间差!当我尝试将结果记录到控制台时,它运行正常
但是!!当我想要返回该整数结果时,它显示这个"{"_h": 0, "_i": 0, "_j": null, "_k": null}" !!! 你有任何建议为什么会发生这种情况?
我尝试了一些无意义的解决方案,但对我没有用!
英文:
I'm trying to make a function that returns a time difference between a server timestamp field's value and an instant client timestamp! When I try to the log the result to the console it works fine
BUT!! when I want to return that int result .. it shows this "{"_h": 0, "_i": 0, "_j": null, "_k": null}" !!! do you have any suggestion why this is happening ?
I tried some of non-sense solutions and nothing worked for me!
答案1
得分: 4
loggingTimeDifference
是一个 async 函数,因此它将始终返回一个 promise。要获取实际结果,您必须要么等待它,要么将回调链接到该 promise。
使用等待的调用如下所示:
const result = await loggingTimeDifference();
console.log(result);
以及链接方式:
loggingTimeDifference().then((result) => console.log(result));
英文:
loggingTimeDifference
is an async function, so it'll always return a promise.
To get actual result you have to either await it or chain callback to the promise.
Call with awaiting would look like this:
const result = await loggingTimeDifference();
console.log(result);
And chaining:
loggingTimeDifference().then((result) => console.log(result));
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论