Friday, 12 July 2019

How to pass dynamically generated values from one file to another one?

Hi all,​I have a situation, where in one file some function produces some value, which I would like to import as an argument in another function within another file, when the value is available. Regardless what I have tried I'm always getting "undefined" for this value.I tried to simulate the problem like this:​mymodule.js:var a = 5; var b = 10; var c; function foo() { setTimeout(function () { c = a + b; return c }, 1000) } module.exports = { c, } and index.js: and index.js:​var module = require('./mymodule.js'); console.log(module.c); ​the output is "undefined", which makes sense, but how can I make sure, that c is calculated and and then available in index.js?

Submitted July 12, 2019 at 05:56PM by reditoro

No comments:

Post a Comment