【发布时间】:2014-03-06 16:41:20
【问题描述】:
我想在 Dart 中级联方法时引用“this”(方法所有者)。
// NG code, but what I want.
paragraph.append( getButton()
..text = "Button A"
..onClick.listen((e) {
print (this.text + " has been has clicked"); // <= Error. Fail to reference "button.text".
}));
我知道我可以通过将其拆分为多行来编写这样的代码。
// OK code, I think this is verbose.
var button;
button = getButton()
..text = "Button A"
..onClick.listen((e) {
print (button.text + " has been clicked");
}));
paragraph.append( button);
由于无法引用级联源对象,我在很多情况下都无法编写更短的代码。有没有更好的方法级联方法?
【问题讨论】:
标签: dart method-cascades