I have the following script:
(function () {
var Module = (function () {
var fctToCall = function () {
alert('Foo');
};
return {
fctToCall: fctToCall
};
})();
var Module2 = (function () {
var init = function () {
var str = 'fctToCall';
Module.str(); // here
};
return {
init: init
};
})();
})();
So I want to call this fctToCall
method by its name - how can I do that? So far I know 3 methods:
- by attaching the function to the window object, but then it wouldn't be local and in closure, and I wouldn't have the access to other local variables
- eval, the best options as far as I see it, but it's still eval, so I don't wanna use it
- this, but it's another architecture, I don't wanna change it
How can I solve this?