javascript - JS Asynchronous calls - my callback method is not working to check an image dimensions -
i have boolean function here called checkurl checks if picture has 100 x 100 pixels. if returns true. there asynchronous call within function check size of image.
function checkurl(url, callback) { var valid; var img = new image(); img.src = url; img.onload = function (callback) { valid = callback(img.width, img.height); }; console.log(valid); return valid; } function nextstep(w, h) { if (w == 100 && h == 100) { return true; } else { return false; } } var pic_valid = checkurl(a_url, nextstep);
i getting error:
callback not defined
within checkurl function. worrying variable valid within checkurl end being invalid.
additional edit: if add console.log(valid); before returning valid undefined. expected?
you define callback here:
function checkurl(url, callback) {
then redefine here:
img.onload = function(callback){
… masks variable give value to.
don't mask it:
img.onload = function(){
Comments
Post a Comment