title: Creating a helper method with jquery/json/getJSON
body: <p>I wanted to create a helper method that can be contained in an included javascript and referenced easily.  The helper method wraps the .getJSON function from jquery ... </p>
  
  <pre><code>function doSomething(someThing) { 
    $.getJSON(theCoolestURLEver, {auth_key:"barfoo", id:someThing}, function(data) {
     console.log(data);
     return data;
    });
  }
  </code></pre>
  
  <p>In my normal HTML pages, what I want to do is: </p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
     &lt;script src="/_/js/myCoolFunctions.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;script&gt;
    var someThing = "foobar";
    var data = doSomething(someThing);
    console.log(data);
  &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The end result is that the console.log comes back as undefined in the second block of code.  I understand now that this has to do with scope or that the page loads and the data isn't available when the &lt; script > tag loads.  So ... if this is true, how do I create a helper method that can hide some complexity that occurs ALL the time?  Like adding the auth_key ... </p>