Return to Snippet

Revision: 80646
at March 23, 2020 17:34 by chrisaiv


Updated URL
https://www.chrisjmendez.com/2014/11/27/js-proper-global-variables/

Updated Code
https://www.chrisjmendez.com/2014/11/27/js-proper-global-variables/

Updated Description
https://www.chrisjmendez.com/2014/11/27/js-proper-global-variables/

Revision: 68103
at November 27, 2014 04:45 by chrisaiv


Initial Code
//Type: Object. 
function setData( d ) { 
	var data = d; 
	getData = function() { 
		return data; 
	} 
} 		

//Type: String.  
function setSection( d ){
	var data = d;
	getSection = function(){
		return data;
	}
}

Initial URL
http://lib-rails.usc.edu:5555/javascripts/edu.usc.Globals.js

Initial Description
It's not a good idea to create global variables unless you do something like this.  From here, all you need to do is setData(YOUR_DATA) and getData()['key']

Initial Title
Proper Global Variables

Initial Tags
javascript

Initial Language
JavaScript