How to call a function which is defined inside an anonymous function but both in the same JS file. Here is my code snippet. How to call _testMethodInside()
from testMethodOutside()
?
// Line 1 to 13 is an existing code from ESRI API
define([
"dojo/_base/declare",
"dojo/_base/html"
], function (
declare,
html
) {
return declare([_WidgetBase, _TemplatedMixin], {
_testMethodInside: function () {
return 'success';
}
});
});
//Call above using this function
function testMethodOutside(){
//How to call _testMethodInside() function from here
}
Follow the Dojo documentation. The
define
block defines a module. You did not specify the module id (which would either be passed explicitly or inferred from the file name), so I will proceed as if the module is namedmy/Example
.The key thing is that because the module is loaded asynchronously, the only place you can safely call it from is the callback function you pass into (AMD)
require
.