tear-offs
tear-offs 是一种特殊的闭包,允许开发者通过 forEach 迭代向 Function 对象直接传递参数。本质是是闭包语法调用的语法糖,具有显著的可读性。
/// This is a example of dart tear-offs.
/// a "tear-offs" is a closure that takes the same parameters as the method and invokes it when you call it.
List<int> a = [1,2,3,4,5,6];
Map<int,String> b = new Map()
..[0]= "0000"
..[1]= "1111"
..[2]= "2222"
..[3]= "3333";
c(int a ,String b){
print(a.toString() + "----"+ b );
}
void main(){
a.forEach(print);
b.forEach(c);
}