1
votes

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

1 Answers

2
votes

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');