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');
Sign up to request clarification or add additional context in comments.

2 Comments

ok, then how can I create Beagle.prototype.run ? does it same rule? context['Beagle']['prototype']['run'] = new JsObject(...)? or prototype has different rule?
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.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.