Suppose I have two files: 1.js and 2.js

In the first file, in the callback, I call the function from the second:

... var json = JSON.stringify({}); 2.someFunction(json); ...

Why in this case in the second file in the function I get undefined ?

    2 answers 2

    1.js:

     var f1 = function() { return function(message) { console.log('i am new function, created inside function from 1.js') console.log(String(message)); } } module.exports = f1(); 

    2.js:

     var f1 = require('./1'); (function somefunc(callback, message) { callback(message); })(f1, 'this string from 2.js'); 

      1.js:

       var f1 = function() { console.log('1.js'); } module.exports = f1; 

      2.js:

       var f1 = require('./1'); (function somefunc(callback) { callback(); })(f1); 

      node 8.4.0

      • Thanks for the answer, but you can make the new variable be created in the f1 function and pass to some function from the 2.js file? - Nikita Bulygin
      • @NikitaBulygin can be, but for this I have to answer again. - n3r0bi0m4n
      • Great, and you can not answer again? - Nikita Bulygin