作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在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);
最佳答案
您不能随意使用this
。
您可以使用简化第二个代码段:
var button = getButton();
paragraph.append(button
..text = "Button A"
..onClick.listen((e) {
print (button.text + " has been has clicked");
}));
关于dart - 在Dart中进行方法级联时如何引用 “this”?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22230610/
我是一名优秀的程序员,十分优秀!