Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 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');
share|improve this answer
    
ok, then how can I create Beagle.prototype.run ? does it same rule? context['Beagle']['prototype']['run'] = new JsObject(...)? or prototype has different rule? –  Sungguk Lim Mar 22 '14 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. –  Justin Fagnani Mar 22 '14 at 4:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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