title: JavaScriptCore -- Passing a function as a parameter to ObjC
body: <p>I have a UIWebView that utilizes JavaScriptCore.  I'm trying to call an ObjC function from an web page.  However, the function needs to be call asynchronously, so I'm passing in a callback function that is called when the async ObjC function is called.  </p>
  
  <p>It is my understanding that JS functions are equivalent to NSBlock via the bridge.  The current code I have is:</p>
  
  <pre><code>context[@"currentUserLocation"] = ^( void(^callback)(NSString* str) )
  {
      NSLog(@"Starting Async Function");
  
      //generic async function
      dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
          NSLog(@"delay complete");
          callback( @"return value" );
      });
  };
  </code></pre>
  
  <p>Is there something fundamentally wrong with what I'm doing?  On the surface it seems like ObjC won't know what context to run the callback function in.  </p>