js-interop:从dart传递javascript对象 [英] js-interop: Passing javascript object from dart
问题描述
我正在努力将javascript移植到dart。
I'm struggling to port javascript to dart..
我的问题是如何创建javascript对象。
原始的javascript代码是
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();
};
现在我有 Beagle
并且它应该 context ['Beagle']
也许?
Now I have Beagle
object. and it should be context['Beagle']
maybe?
如何创建javascript obejct?和原型
?
how can I create javascript obejct?? and with prototype
?
推荐答案
c> Beagle 应在 context ['Beagle']
上可用。要从Dart创建一个新的实例,你需要使用 JsObject
构造函数:
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']);
一旦你这样做,你可以调用 run
与 callMethod
方法:
Once you do that you can call run
with the callMethod
method:
beagle.callMethod('run');
这篇关于js-interop:从dart传递javascript对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!