Bad Coder
Bad Coder

Reputation: 906

passing arguments with a call back function

function images(url, somextra, callback)
{
    var img = new Image();
    img.onload = function() {
        callback(url , somextra);   
    };
}

function call(url, extra)
{
}

images(someurl, stuffs, call);

When I am passing 2 arguments my programs just hangs. How can I pass two arguments and a callback function in my images function?

Upvotes: 0

Views: 106

Answers (2)

user3861247
user3861247

Reputation:

You should clear you concept !!!! it does not matters if one or more than one argument.

img.src = url

try to add image url after imag.onload

Upvotes: 1

iamrobin
iamrobin

Reputation: 108

You are setting a the callback up on the onload event, but you are not loading the image.

Try setting up the source for the image like this.

function images(url ,somextra , callback)
{
    var img = new Image();
    img.onload = function(){
         callback(url , somextra);   
    };
    // set the source url here
    img.src = "example/url/image.png"
 }

 function call(url , extra){

 }
 images( someurl , stuffs , call);

Otherwise your onload event never fires and therefore the callback is not called.

Upvotes: 1

Related Questions