title: How can I make my variable contained within this function global?
body: <p>I'm trying to store data from a variable contained within a function that receives JSON data. This variable typically has the json data returned stored in it. For testing purposes, instead of storing the actual JSON data returned inside the variable, I just supplied the variable with an array of objects. The variable is window.mySHows and as you can see, this is the variable I'm attempting to make global by using "window" in front of my variable. In this example, I'm using an array of objects to represent the JSON data that this variable will have, instead. The problem is, I can not reach this variable outside of the function it's in. I tried to make it global but that's not working. Below is my code: (I'm also using angular JS) </p>
  
  <pre><code> function getStuff(num, onContents){
   $.getJSON('http://whateverorigin.org/get?url=' + encodeURIComponent('http://catholic.com/api-radio/' + num) + '&amp;callback=?', function(data){
     //call the oncontents callback instead of returning
     onContents(data.contents);
   });
   }
  
   //when calling getstuff, pass a function that tells what to do with the contents
   getStuff(6387, function(contents){
   var res = (contents);
   //I'm not going to store res in window.myShows, instead I'm adding the test JSON
   window.myShows = [{
      "from": "Steve Jobs",
      "subject": "I think I'm holding my phone wrong :/",
      "sent": "2013-10-01T08:05:59Z"
   },{
      "from": "Ellie Goulding",
      "subject": "I've got Starry Eyes, lulz",
      "sent": "2013-09-21T19:45:00Z"
   },{
      "from": "Michael Stipe",
      "subject": "Everybody hurts, sometimes.",
      "sent": "2013-09-12T11:38:30Z"
   },{
      "from": "Jeremy Clarkson",
      "subject": "Think I've found the best car... In the world",
      "sent": "2013-09-03T13:15:11Z"
   }];
  
   });
  
  
   //$scope.shows does not get the data from window.myShows
   $scope.shows = window.myShows;
  
   // -- Native navigation
   steroids.view.navigationBar.show("Show index");
  
   });
  </code></pre>