Accessing variables from other functions without using global variables


var MyApp = {}; // Globally scoped object
function foo(){
MyApp.color = 'green';
}
function bar(){
alert(MyApp.color); // Alerts 'green'
}

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.