假设在Dart(DartPad)中,我们有:
String a = "I am higher in the scope chain"; void main() { String a = "I am lower in the scope chain, but I have the same name"; print(a); }
是否有一个关键字可以用来打印父作用域中的变量,例如:
print(parent.a)
或
print(this.a)
?(这些不起作用)。
23c0lvtd1#
如果您的文件名是'some_dart_file. dart',则可以执行此操作
import './some_dart_file.dart' as parent show a; String a = "I am higher in the scope chain"; void main() { String a = "I am lower in the scope chain, but I have the same name"; print(parent.a); }
1条答案
按热度按时间23c0lvtd1#
如果您的文件名是'some_dart_file. dart',则可以执行此操作