1

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 Answer 1

2

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');
2
  • ok, then how can I create Beagle.prototype.run ? does it same rule? context['Beagle']['prototype']['run'] = new JsObject(...)? or prototype has different rule? Mar 22, 2014 at 1:20
  • 1
    I don't understand your question. Given the above JavaScript, the Dart I showed you is how you access it. Are you looking to define your JavaScript prototype from Dart? It's doable, but unless there's a very good reason, I'd keep your JavaScript in JavaScript. Mar 22, 2014 at 4:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.