Calling function and running it
<p>I am quite new to objects and OOP. I really don't know how to explain it well but I'll try.</p>

<p>So I am trying to read though JSON with JS, the JSON is passed from PHP. This would be easy if all of the information was on the same html page, but I' am trying something that I am new too.</p>

<p>So let me show my code...</p>

<p>First is the JS which is in app.js</p>

<pre><code>   var Donors = function(){
    var api = this.list;

    $(document).ready(function(){
      $.getJSON(api, function(data){
        var donorObj = data.payload;
        $.each(donorObj, function(i, donor){
          //console.log(donor.ign);
        });
      });
    });

   }
</code></pre>

<p>What I <em>want</em> this part to do is read from the JSON I'm giving it and console.log each name (or donor.ign) when the document is ready. </p>

<p>On the html page, or header.php </p>

<pre><code>&lt;script&gt;
$(function(){
    var list = &lt;?php cbProxy(); ?&gt;;
    var Dons = new Donors();
    Dons.list = list;
    });
&lt;/script&gt;
</code></pre>

<p>the data that's in list is the below JSON. You already know what the rest does, it just passes the JSON to the <code>Donors()</code> function.</p>

<p>JSON example:</p>

<pre><code>{
"code": 0,
"payload": [
{
"time": 1349661897,
"packages": [
"49381"
],
"ign": "Notch",
"price": "15.99",
"currency": "USD"
}
</code></pre>

<p>I'm use to just making functions and calling it on the same page or file and this is my first doing this kind of function. How can I get the function to run with the data I sent it so it <code>console.log()</code> each name?</p>

<p>I did try</p>

<pre><code>console.log(Donors());
</code></pre>

<p>Which only logged <code>undefined</code>.</p>

<p>New code:</p>

<p>app.js</p>

<pre><code>   var Donors = function(api){

    this.list = api;

    $(document).ready(function(){
      $.getJSON(this.list, function(data){
        var donorObj = data.payload;
        $.each(donorObj, function(i, donor){
          console.log(donor.ign);
        });
      });
    });

   }
</code></pre>

<p>index.php/inline script</p>

<pre><code>&lt;script&gt;
$(function(){
    var list = &lt;?php cbProxy(); ?&gt;;
    var dons = new Donors(list);
});
&lt;/script&gt;
</code></pre>
