As far I know primitive values (e.g. numbers, string, …) are passed by value.
mystr:string="abc";
chgstr (x:string)
{
x = "xxx";
}
console.log (this.mystr); // abc
this.chgstr (this.mystr);
console.log (this.mystr); // abc -> no change!
Complex objects (e.g. objects, arrays) are passed by reference.
myobj:any={abc:123};
chgobj (x:any)
{
x["abc"]="000";
}
console.log (this.myobj); // Object {abc: 123}
this.chgobj (this.myobj);
console.log (this.myobj); // Object {abc: 000} -> changed
Is it good style to expect a parameter to be a complex type and use the pass-by-reference (e.g. my sample of chgobj) or would it be better to explicitly return the changes object?
chgobj (x:any):any
{
x["abc"]="000";
return x; // return!
}
myobj = this.chgobj (this.myobj); // use the return-value