The loaded script can only access global variables.
You've got two options:
- Temporary create a global variable.
- Call the injected function from within the callback.
Code for method 1:
var tVar = 'Hello World!';
$.getScript('js/setting.js');
window.get_tVar = function() {
delete window.get_tVar; // Clean-up
return tVar;
};
// In settings.js:
function logic() {
var tVar = window.get_tVar();
}
Code for method 2:
var tVar = 'Hello World!';
$.getScript('js/setting.js', function() {
newGlobalFunc(tVar);
});
// In settings.js:
function newGlobalFunc(tVar) {
// Do something
}