how do you get the response back into the instance of the object?
<p>If you've written a class in JavaScript that calls a remote service's API, and that remote API offers a callback, how do you get the response back into the instance of the object that made the request?</p>

<p>I'll try to give you a very basic example FOO for making cross domain calls to BAR service which offers a callback. Please ignore the usual security concerns, (I own both servers).</p>

<pre><code>function FOO() {
    this.response = null;

    this.execute = function(url) {
        var script = document.createElement('script');
        script.src = url;
        document.getElementsByTagName('head')[0].appendChild(script); 
    }

    this.catch = function(response) {
        this.response = response;
    }
}


var sample = new FOO();

sample.execute('http://barservices.com/sample/?callback={ plshelphere: this.catch}');
</code></pre>

<hr>

<p>I have a way to make this work, but I'm curious if there is an "accepted approach" here.</p>

<p>Anyone have thoughts for me?</p>
