Reputation: 3391
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
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