我需要在回调函数中从main访问变量.回调函数只有一个参数Event.除了将其设置为全局变量之外,从回调访问变量的首选方法是什么?是否可以将其作为额外参数传递给回调?
而不是listen(callbackFunction),使用listen((SomeEvent e) => callbackFunction(e, myOtherParameter));.
例如,
document.querySelector("div#someElement")
.onClick.listen((MouseEvent e) => callbackFunction(e, myOtherParameter))
Run Code Online (Sandbox Code Playgroud)
将调用以下函数
void callbackFunction(MouseEvent e, myOtherParameter) {
// Do something with your parameter
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1331 次 |
| 最近记录: |