My question is how to access functions which have been created in other files.
I have 3 files checkSelection.js
polishToEnglish.js
polishToGerman.js
.
Struct of file 1 is:
//some code
function selectOptions() {
//some code
if (document.getElementById("Pol2Eng").checked) {
polishToEnglish(polish2EnglishDictionaryPath, polishExpression);
} else if (document.getElementById("Pol2Ger").checked) {
polishToGerman(polish2EnglishDictionaryPath, polish2GermanDictionaryPath, polishExpression);
}
//some code
}
The second one is:
function polishToEnglish(polish2EnglishDictionaryPath, polishExpression){
//some code
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState === 4) {
var lines = xmlhttp.responseText;
dictionary = lines.split('\n');
return findTranslation(dictionary, polishExpression);
}
};
//some code
}
function findTranslation(dictionary, word) {
dictionary.forEach(function(line){
if(line.includes(word)) {
result = line.split(';')[1];
}
});
return result;
}
And the third one is:
function polishToGerman(polish2EnglishDictionaryPath, polish2GermanDictionaryPath, polishExpression) {
engWord = polishToEnglish(polish2EnglishDictionaryPath, polishExpression);
}
The problem is in the third file. engWord
is displayed as undefined.
I've tried some solutions like making the functions window.polishToEnglish = function(...){}
, but with no effect.
Any ideas how to resolve the problem?