I just started with require.js today. I was planning to create module and have sucessfully created one.
Now I want to make a recursive call to a return function in the module. How to do that?
My module.
define(['jquery', 'underscore'], function ($, _) {
var thisModule = this;
return {
moduleFuntion: function (data) {
//Code
...
//How to call moduleFunction here.
}
}
});
I have tried
modelFunction();
and
thisModule.moduleFuntion();
I think splitting the code into another function rather than the return function and caling that recursively works
define(['jquery', 'underscore'], function ($, _) {
var thisModule = this;
function codeFunction(data) {
//Code
....
codeFunction()
}
return {
moduleFuntion: function (data) {
codeFunction(data);
}
}
});
But instead of that is that possible in my current code?
Update :
I have solved issue by
define(['jquery', 'underscore'], function ($, _) {
return {
moduleFuntion: function (data) {
//Code
...
var moduleObject = require('jsonviewer');
moduleObject.moduleFuntion(dataNew);
}
}
});
Is this this the correct approach?
Note: I'm new to require so I would like to get experts opinion on the path I took