I need to have a value returned by and event handler into the function that initiates the event in the first place, just to return the value that will be received only in the event handler. I believe there should be an easy way to accomplish this or to attack the problem from a different angle.
What I actually need to do is:
- Create a new img DOM object to feed dataURL into (the dataURL is coming from canvas.toDataURL())
- img.onload will let me return the dataURL
I’m using jQuery if that helps somehow but don’t have to of course.
In my understanding I can’t rely on the img to have the data immediately, and it feels stupid to use timeouts to wait for the event to fire and use some global variable, especially since a few might be processed in parallel.
For even more background, this is all for resizing images before (multi-)uploading them with HTML5 engine.
Thanks even for reading, and for any tips of course 🙂
Thanks,
Igor
It doesn’t make sense to return values from an event handler. Events happen when they happen, and the handler is called by the browser at that time. Thus, there’s no code expecting any return value; there’s nowhere for it to go.
Instead, simply do whatever it is you need to do inside the event handler.