简体   繁体   English

如果在 Node.js 中定义的全局变量在几秒钟后没有改变,我如何检查它

[英]How can I check if a global variable that defined in Node.js if it's not changing after seconds

I wrote an app in nodejs but having logic problem with variable.我在 nodejs 中编写了一个应用程序,但变量存在逻辑问题。 I'm looking for help with this issue.我正在寻求有关此问题的帮助。

Well, i have a global integer variable named "global_something" I need a function that check if "global_something" not changing after 1000ms or 2000ms好吧,我有一个名为“global_something”的全局整数变量我需要一个函数来检查“global_something”在 1000 毫秒或 2000 毫秒后是否没有改变

How i can do that ?我怎么能这样做?

Thanks!谢谢!

You have to make 2 variable for that你必须为此创建 2 个变量

var original_global = 'Test';
var copy_original_global; // save this field in database or json file for compare  

setInterval(()=>{
  if(!copy_original_global){
      copy_original_global = original_global;
       return
 } 
 if(original_global != copy_original_global){
  console.log('Changed')
 }
}, 3000);

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

相关问题 如何检查 Node.js 中是否定义了变量? - How can I check whether a variable is defined in Node.js? 在node.js中经过几秒钟后如何检查函数结果? - How can i check a function result after multi seconds in node.js? Node.js:使用csvtojson将CSV转换为JSON后,如何在全局变量中存储jsonObj - Node.js: How can i store the jsonObj in a global variable after converting CSV to JSON by using csvtojson 如何检查 Node.js 中是否设置了环境变量? - How can I check if an environment variable is set in Node.js? 文档未在 node.js 上定义 - 如何将另一个 .js 文件中的变量导入 node.js 服务器? - Document is not defined on node.js - How can i import a variable from another .js file to node.js server? 如何从回调函数中修改全局变量。 在 node.js 中 - How can i modify a global variable from within a callback function . in node.js (Node.js) 如何将转换后的 .JSON 文件保存在全局变量中? - (Node.js) How can I save in a global variable my converted .JSON file? 全局变量未在 cron 文件中的 node.js 服务器上定义 - global variable is not defined on node.js server in a cron file 如何在node.js中使用全局变量? - How to use global variable in node.js? 如何在 node.js 中监视定义的变量 - how spy a defined variable in node.js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM