You have to pass the args variable to the anonymous function, but the anonymous function does not visibly need the args variable, so you have to memorize when Dojo needs the args variable, but the Dojo help page doesn’t say! So, when does Dojo need the args variable?
var init = function(){
var contentNode = dojo.byId("content");
dojo.xhrGet({
url: "js/sample.txt",
handleAs: "text",
load: function(data,args){
// fade out the node we're modifying
dojo.fadeOut({
node: contentNode,
onEnd: function(){
// set the data, fade it back in
contentNode.innerHTML = data;
dojo.fadeIn({ node: contentNode }).play();
}
}).play();
},
// if any error occurs, it goes here:
error: function(error,args){
console.warn("error!",error);
}
});
};
dojo.addOnLoad(init);
To clarify: you are referring to the
argsargument you have in your code sample that is part of the function definitions for theloadanderrorcallbacks:You only need the
argsvariable if you need to use it. Dojo itself does not need it. Normally you should not need it. The first argument should be the result you are looking for.However, if you need to access the raw
XMLHttpRequestobject, thenargs.xhrwill hold it.Similarly, if you want access to the original object you passed to
dojo.xhrGet(because you stored some sort of state on it), you can get it atargs.args(for this reason, I normally name that argumentioArgs, so it would then beioArgs.args).