foo.js:
function doStuff() {
require(['path/to/bar/'], function(bar) => { //code// })
}
However, bar calls a function (let's call it func) which is not defined in bar, only called in the code. How can I define func for use in bar? Something like:
bar.js
function doMoreStuff() {
func()
}
foo.js
function doStuff() {
require(['path/to/bar/'], function(bar) => {
bar.func = () => { console.log("hello world!") }
bar.doMoreStuff()
})
}
Note: I know bar.js isn't written as a module should be, pretend it is - everything works in my code but I get an error that the function isn't defined (because it isn't, hence the question on how to define it)