2

I want to access the object itself within a listen-callback.

SomeObject o = new SomeObject()
    ..onEvent.listen((Event ev){

        //now I want to access Object o.

    });

It works if I call onEvent.listen after o is created, but I want to access it by the constructor, because some events are fired during construction. Is it somehow possible to access the object within this callback?!

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
NaN
  • 3,501
  • 8
  • 44
  • 77

1 Answers1

3

What you try to do is recursive initialization.
You can do it like:

SomeObject o;
o = new SomeObject()
    ..onEvent.listen((Event ev){

        //now I want to access Object o.

    });

See https://code.google.com/p/dart/issues/detail?id=10751 for more details.

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567