问题
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