【发布时间】:2013-05-08 22:03:14
【问题描述】:
我使用下面来查看 dart 如何调用传入其他方法的方法,以查看传入的方法将/可以在什么上下文中调用。
void main() {
var one = new IDable(1);
var two = new IDable(2);
print('one ${caller(one.getMyId)}'); //one 1
print('two ${caller(two.getMyId)}'); //two 2
print('one ${callerJustForThree(one.getMyId)}'); //NoSuchMethod Exception
}
class IDable{
int id;
IDable(this.id);
int getMyId(){
return id;
}
}
caller(fn){
return fn();
}
callerJustForThree(fn){
var three = new IDable(3);
three.fn();
}
那么caller 管理器如何在没有上下文的情况下调用其参数fn,即one.fn(),以及为什么callerJustForThree 无法在为其定义了该函数的对象上调用传入的fn ?
【问题讨论】: