I need to return a variable from a function with anonymous functions inside of it.
Like this:
function resize(f) {
...
reader.onloadend = function() {
...
image.onload = function() {
...
finalFile = dataURItoBlob(canvas.toDataURL(fileType));
}
}
}
I need to return the variable finalFile to another variable that called this function, but it keeps returning null, even if I set Global variable it doesn't work. Any idea?
onload
and functions like it are asynchronous and need callback functions.
You cannot return from them.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.