Functions passing parameters by value


#1

Looks like functions are not able to pass their arguments by reference?

Is this is expected? Is there anyway I can get around it?

function test(arg)
{
    arg.id = 3;
}
var o = {id:1};
test(o);
this.say("id: " + o.id"); // always says id: 1

#2

It’s not exactly that they are passed by value instead of reference, but that things going in and out of function boundaries have CodeCombat’s API protection applied during the transpiler, which means you can’t write their properties. We probably don’t need it for this case, since you defined your own function, so any argument you passed to it is already protected. I’ll track it over here in GitHub.