title: Creating a JavaScript callback in an iframe
body: <p><strong>UPDATE:</strong> The back-end service was powered by an ASP.Net AJAX Web Service proxy.</p>
  
  <p>1) The main page has two global objects, one for the back end connections (<code>Svc</code>) and another for handling the DOM (<code>Main</code>). It also dynamically loads documents into an iframe.</p>
  
  <p>2) These iframes need to access services provided by <code>Svc</code>, and also supply a callback function.</p>
  
  <p>3) The problem - passing a function created in the iframe to the parent frame, it's treated as an object not a function and cannot be invoked.</p>
  
  <p>Can anyone provide a better solution than what I've got currently in the iframe:</p>
  
  <pre><code>var Main = parent.Main,
      Svc = parent.Svc;
  
  Svc.method(data, Main.createCallback(
      function(response) {}
  ));
  </code></pre>
  
  <p>and in the parent frame:</p>
  
  <pre><code>Main.createCallback = function(func) {
      return function() {
          func.apply(func, arguments);
      }
  }
  </code></pre>