0

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?

1
  • 1
    Are you checking the variable before it has been set by that async operation? Commented Nov 18, 2013 at 21:17

1 Answer 1

1

onload and functions like it are asynchronous and need callback functions.

You cannot return from them.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.