Search code examples
javascriptecmascript-6ecmascript-5ecma

Call exported function in exported function


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.


Solution

  • 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.