[英]How to return variable from anonymous function
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. 我需要将变量finalFile返回到另一个调用此函数的变量,但是即使我设置了全局变量,它也始终返回null。 Any idea?
任何想法?
onload
and functions like it are asynchronous and need callback functions. onload
和类似的函数是异步的,需要回调函数。
You cannot return from them. 您不能从他们那里回来。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.