D
Daniel Kabs
Hello,
loading images or refreshing IFRAME content is done asynchronously in
Javascript. You just assign a value to the src attribute of the object
and you are done. Once loading is finished, the event handler will
inform you. This is wanted behaviour in most situations but sometimes
its just a pain.
Imagine, you have this kind of "call" in a deeply nested function. As it
will return immediately, how do you wait for the result? You can't. You
have to use callbacks. "It's a little awkward to
have to string together calling functions and callbacks all over the
place, particularly when I need to maintain some kind of state between
those calls. " ([email protected]).
Can I wrap something like this
function ImgObj(obj) {
var me = this;
this.load = function() {
obj.onload = function() { me.loaded()};
obj.src = "bild.jpg";
}
this.loaded = function() {
alert("Image loaded!");
}
}
with a synchronous facade so that calls to a "load" function return
either the image object or null in case of a timeout?
Cheers
Daniel Kabs
Germany
loading images or refreshing IFRAME content is done asynchronously in
Javascript. You just assign a value to the src attribute of the object
and you are done. Once loading is finished, the event handler will
inform you. This is wanted behaviour in most situations but sometimes
its just a pain.
Imagine, you have this kind of "call" in a deeply nested function. As it
will return immediately, how do you wait for the result? You can't. You
have to use callbacks. "It's a little awkward to
have to string together calling functions and callbacks all over the
place, particularly when I need to maintain some kind of state between
those calls. " ([email protected]).
Can I wrap something like this
function ImgObj(obj) {
var me = this;
this.load = function() {
obj.onload = function() { me.loaded()};
obj.src = "bild.jpg";
}
this.loaded = function() {
alert("Image loaded!");
}
}
with a synchronous facade so that calls to a "load" function return
either the image object or null in case of a timeout?
Cheers
Daniel Kabs
Germany