Reputation: 1833
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?
Upvotes: 0
Views: 109
Reputation: 3933
onload
and functions like it are asynchronous and need callback functions.
You cannot return from them.
Upvotes: 1