There are many instances were you might like to define global variables, that can be used anywhere.
This does not work:
1 2 3 4 5 |
var my_variable = 1 $.getScript( "my_script.js", function() { alert(my_variable); }); |
This works:
1 2 3 4 5 |
window.my_variable = 1 $.getScript( "my_script.js", function() { alert(window.my_variable); }); |
In case of the first $.geScript function(){…} the my_variable is only availble within the scope of the function. In the second the variable is assigned to the window object and can be used within.