js-interop: Passing javascript object from dart

£可爱£侵袭症+ 提交于 2019-12-11 13:09:05

问题


I'm struggling to port javascript to dart..

My problem is how to create javascript object. original javascript code is

  function Beagle() {
    this.argv_ = null;
    this.io = null;
  };
  Beagle.prototype.run = function() {
    this.io = this.argv_.io.push();
  };

Now I have Beagle object. and it should be context['Beagle'] maybe?

how can I create javascript obejct?? and with prototype?


回答1:


You are correct that Beagle should be available at context['Beagle']. To create a new instance from Dart you need to use the JsObject constructor:

var beagle = new JsObject(context['Beagle']);

Once you do that you can call run with the callMethod method:

beagle.callMethod('run');


来源:https://stackoverflow.com/questions/22567116/js-interop-passing-javascript-object-from-dart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!