user1338952
user1338952

Reputation: 3391

is there some sort of scope resolution operator to get to a name outside the class

In the following code I would like the function globalFoo to access the file level foo. What is the way to do that?

class Foo {
  foo() => print('Foo.foo');
  globalFoo() => foo();  // How to call top level foo?
}

foo() => print('Global.foo');

main() {
  final foo = new Foo();
  foo.globalFoo();
}

Upvotes: 3

Views: 287

Answers (1)

Alexandre Ardhuin
Alexandre Ardhuin

Reputation: 76273

You can create an alias :

class Foo {
  foo() => print('Foo.foo');
  globalFoo() => _foo();
}

foo() => print('Global.foo');
final _foo = foo;  // Alias foo with _foo

main() {
  final foo = new Foo();
  foo.globalFoo();
}

Upvotes: 4

Related Questions