Have a look at the following
What I get is 0 0 10 i.e. setdirect doesn't work but setindirect does.
It looks like the only way I can modify a parameter in a function is to pass a structure to it. Is this assumption correct or is there a "correct" way of modifying a parameter? Is there a way of getting round the call-by-value mechanism?
Code:
function struct () {
this.value = 0;
}
// Direct parameter
function setdirect (xx) {
xx += 10;
}
function setindirect (xx) {
xx.value += 10;
}
var yy = new struct ();
WScript.echo (yy.value);
setdirect (yy.value);
WScript.echo (yy.value);
setindirect (yy);
WScript.echo (yy.value);
It looks like the only way I can modify a parameter in a function is to pass a structure to it. Is this assumption correct or is there a "correct" way of modifying a parameter? Is there a way of getting round the call-by-value mechanism?