title: Is it possible to define valid JavaScript's functions from Dart?
body: <p>Sorry for my broken English.
  I'm new to the Dart language. I have been searching for a way to communicate between JS and Dart. I want to call jQueryUI code from Dart.</p>
  
  <p>When I create a jQueryUI's dialog, the HTML and JS code will be like this:</p>
  
  <h2>HTML code:</h2>
  
  
  
  <pre class="lang-dart prettyprint-override"><code>...
  &lt;button id="btn1"&gt;OPEN&lt;/button&gt;
  &lt;div id="msg"&gt;
  Hello, world!
  &lt;/div&gt;
  ...
  </code></pre>
  
  <h2>JS code:</h2>
  
  <pre class="lang-dart prettyprint-override"><code>$('#btn').click( function() {
    $('#msg').dialog('open');
  });
  
  $('#msg').dialog({
    autoOpen: false,
    buttons: {
      "OK": function() {
        $(this).dialog('close');
      }
    },
    title: "Dialog",
    modal: false,
    show: 'fold',
    hide: 'puff'
  });
  </code></pre>
  
  <p>So, I tried to convert these JS code into Dart code.
  However, when I write these test Dart codes below, I got an error message below.</p>
  
  <pre class="lang-dart prettyprint-override"><code>Breaking on exception: Closure call with mismatched arguments: function 'call'
  </code></pre>
  
  <h2>Dart code:</h2>
  
  <pre class="lang-dart prettyprint-override"><code>import 'dart:html';
  import 'dart:js' as js;
  
  void dartFunc() {
    print("test");
  }
  
  void main() {
  
    js.JsObject btn = js.context.callMethod(r'$', ['#btn']);
    btn.callMethod('click', [dartFunc]); //-----&gt; ERROR!
    //...
  }
  </code></pre>
  
  <p>But, when I wrote a JS function and Dart code below, the error disappeared and the program ran successfully.</p>
  
  <h2>JS code:</h2>
  
  <pre class="lang-dart prettyprint-override"><code>function jsFunc() {
    console.log("test");
  }
  </code></pre>
  
  <h2>Dart code:</h2>
  
  <pre class="lang-dart prettyprint-override"><code>import 'dart:html';
  import 'dart:js' as js;
  
  void dartFunc() {
    print("test");
  }
  
  void main() {
  
    js.JsObject btn = js.context.callMethod(r'$', ['#btn']);
    btn.callMethod('click', [jsFunc]); -----&gt; SUCCESS!
    //...
  }
  </code></pre>
  
  <p>To find out this problem, I performed some tests.
  When I print both functions(jsFunc() and dartFunc()) to the console from Dart, like</p>
  
  <h2>Dart code:</h2>
  
  <pre class="lang-dart prettyprint-override"><code>...
  js.context['dartFunc'] = dartFunc;
  print(js.context['jsFunc']);
  print(js.context['dartFunc']);
  ...
  </code></pre>
  
  <p>the results are below.</p>
  
  <pre class="lang-dart prettyprint-override"><code>function jsFunc() {
    console.log("test");
  }
  function () {
    return func(Array.prototype.slice.apply(arguments));
  } 
  </code></pre>
  
  <p>Apparently the result of <code>print(js.context['dartFunc'])</code> is odd.</p>
  
  <p>Can anyone help?
  Is it possible to define valid JavaScript's functions from Dart?</p>
  
  <p>Thanks for reading to the end :)</p>