passer le nom d'une fonction comme paramètre d'une autre fonction?
Bonjour,
j'essaie de comprendre un bout de code javascript.
en fait, je n'ai pas compris le fait de passer le nom d'une fonction comme paramètre d'une 2eme.
Je ne sais pas si ça a un but bien particulier?
à mon avis, il fallait appeler la fonction directement.
Je ne pense pas qu'il l'utilise comme un Objet...
voici le code :
passer la fonction ajaxCallback comme argument :
Code:
doAjax(ajaxTarget+"?thres="+threshold,ajaxCallback,0,0);
fonction appelée :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| function doAjax(ajaxTarget,ajaxCallBack,timeout,timeoutCallBack){
var xhr;
var xhrTimer;
try{ xhr = new XMLHttpRequest(); }
catch(e){ xhr = new ActiveXObject('Microsoft.XMLHTTP'); }
xhr.onreadystatechange = function(){
if(xhr.readyState == 4) {
ajaxCallBack(xhr.status,xhr.responseText);
if(timeout > 0)
clearTimeout(xhrTimer);
}
};
xhr.open("GET", ajaxTarget, true);
if(timeout > 0)
xhrTimer = setTimeout(function() { xhr.abort(); timeoutCallBack();}, timeout);
xhr.send(null);
} |
la fonction passée comme argument :
Code:
1 2 3 4 5 6 7 8
| function ajaxCallback(status,text){
document.getElementById("loader").style.visibility = "hidden";
document.getElementById("launch").style.visibility = "visible";
if(status == 200 && text != "") {
text = parseInt(text/10.24);
document.getElementById("alert").innerHTML="Brightness: " + text + " %";
}
} |
une idée?
merci pour votre aide.