Proper Global Variables


/ Published in: JavaScript

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']


Copy this code and paste it in your HTML
  1. //Type: Object.
  2. function setData( d ) {
  3. var data = d;
  4. getData = function() {
  5. return data;
  6. }
  7. }
  8.  
  9. //Type: String.
  10. function setSection( d ){
  11. var data = d;
  12. getSection = function(){
  13. return data;
  14. }
  15. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.