Skip to content
Advertisement

Is it possible to export a function that calls another function defined in the file where the module is imported from?

Example:

JavaScript

where func2 is only available in the file where we do:

JavaScript

Is this possible?

Advertisement

Answer

No, func2 must be defined when you create a func1, otherwise it will be undefined and will throw a runtime exception when func1 will be invoked.

You can pass func2 as an argument of func1 and invoke it inside.

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement