I need to access a variable from main in a callback function. Callback functions only have one parameter, Event. What would be preferred way to access a variable from callback, other than setting it as global variable? Is it possible to pass it to callback as an extra parameter?
Rather than listen(callbackFunction), use listen((SomeEvent e) => callbackFunction(e, myOtherParameter));.
For example,
document.querySelector("div#someElement")
    .onClick.listen((MouseEvent e) => callbackFunction(e, myOtherParameter))
will call the following function
void callbackFunction(MouseEvent e, myOtherParameter) {
   // Do something with your parameter
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With