-1

I need call exported function in another one.

Here is my first fucntion which is called:

import initialization from './initialization';
export default (a, b) => {
  console.log('called 1.')
  initialization();
};

and here is my another exported function in separated file (initialization/index.js) which I want to call in previous function.

export default () => {
  function someInnerFunc() {
     //...
  }
  return () => {
    console.log(called 2.);
  };
};

In console I have message only "called 1." so I guess second function isn't called. Can you help me to fix it? Thank you.

EDIT:

first function is called in my app.js like that:

handlers(foo1, foo2);

I am sure that first function is called because I got message in console, problem is with second one.

Denis Stephanov
  • 4,563
  • 24
  • 78
  • 174
  • It looks like you're never actually calling the first function. – djfdev May 18 '18 at 15:49
  • Which line is supposed to call the first function? How do you import those functions? [mcve] please. – JJJ May 18 '18 at 15:50
  • @djfdev first function is called but in my app js script ... I just doesn't put it here – Denis Stephanov May 18 '18 at 15:50
  • @JJJ check my updated question please .. I doesn't put calling first function here because I guess it is irrelevant. Message of first function is in console so it is 100% called – Denis Stephanov May 18 '18 at 15:53
  • So if the problem is with the second function why aren't you showing how you're importing it? It's a function that returns a function so you have to call it twice for the console log to appear, but without seeing a complete example it's just guessing. – JJJ May 18 '18 at 15:54
  • I added import above code – Denis Stephanov May 18 '18 at 15:55
  • The function you import as `initialization` doesn't output anything. It declares `function someInnerFunc()` then returns another function that you never call. – axiac May 18 '18 at 15:57
  • @axiac is possible edit my example to call initialization function directly ? – Denis Stephanov May 18 '18 at 16:03
  • What is the point of `function someInnerFunc() { //... }`?! You should just put that in the module scope. – Bergi May 18 '18 at 17:40

1 Answers1

1

Your initialization method returns another function.

You will need to execute that function in order to see the second log message.

import initialization from './initialization';
export default (a, b) => {
  console.log('called 1.')
  var initResult = initialization();
  initResult();
};

Although it is unclear what you are trying to achieve with this code.

Gabriele Petrioli
  • 191,379
  • 34
  • 261
  • 317