Access the caller instance from a function.

43 views
Skip to first unread message

Gonzalo Chumillas

unread,
Jul 18, 2016, 12:05:38 PM7/18/16
to Dart Misc
How could I access the "caller" instance from a function. The following code throws a syntax error:

// Error: Local variables cannot be referenced before they are declared
Function listener = (Event event) {
 
print(listener);
};

I would like to access the "listener" variable from inside the function.
Thanks.

Gonzalo Chumillas

unread,
Jul 18, 2016, 1:01:35 PM7/18/16
to Dart Misc
What a silly question :D Solved:

Function listener;

listener
= (Event event) {
 
print(listener);
}

Bob Nystrom

unread,
Jul 18, 2016, 1:36:28 PM7/18/16
to General Dart Discussion
Or even:

  listener(Event event) {
    print(listener);
  }

:)

– bob


--
For other discussions, see https://groups.google.com/a/dartlang.org/
 
For HOWTO questions, visit http://stackoverflow.com/tags/dart
 
To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.

Gonzalo Chumillas

unread,
Jul 18, 2016, 2:44:19 PM7/18/16
to Dart Misc
Thanks :) I like it even better.
Reply all
Reply to author
Forward
0 new messages