I'm experiencing an issue with RequireJS where I'm not able to export a set of functions when I have a require statement.
Let's assume I have a file called mySubFile.js, where, first I need to inject jQuery and then another dependency. Now, Let's suppose I have myFunction and I want to export it in order to get called from another file.
define('mySubFile', ['jquery'], function ($) {
require(['dependency1'], function (dependency1) {
let myFunction = function(){ return "Hey There"; }
return : {
myFunction : myFunction
}
});
});
Now let's assume that I want to call that function from myFile.js:
define('myFile', ['jquery'], function ($) {
require(['mySubFile'], function (mySubFile) {
console.log(mySubFile.myFunction());
});
});
This does not work. I get:
Cannot read property 'myFunction' of undefined.
On the other side, If I define mySubFile.js as follows:
define('mySubFile', ['jquery', 'dependency1'], function ($, dependency1) {
let myFunction = function(){ return "Hey There"; }
return : {
myFunction : myFunction
}
});
I can access myFunction but I NEED to first resolve jQuery.
I'm struggling trying to find a solution to this but still haven't found anything.
How Can I Solve this?