Question about the pass by value or pass by ref

Started by
3 comments, last by GameDev.net 17 years, 8 months ago
Hi I sometime confused with pass by ref and pass by value. I know the idea but sometime not quite sure when is pass by ref or pass by value. e.g. function A(Object a) { return a; } var b = blah; and b has a variable of x = 4 var a = A(b); calling the A function and pass b as an parameter a.x = 6; change the variable a's x to 6.... at the end will b.x = 6 or b.x = 4
Advertisement
what language are you using ?
Quote:Original post by Anonymous Poster
what language are you using ?



Currently writing in ActionScript but Aren't they similar with other language like c#.
Quote:Original post by kbundy
Quote:Original post by Anonymous Poster
what language are you using ?



Currently writing in ActionScript but Aren't they similar with other language like c#.


yes, but even though many languages have a C like syntax doesn't mean that they pass by value and/or reference at exactly the same time.

however i don't think actionscript would pass an object by value. php however always passes everything by value unless you specify otherwise.

the easiest way to find out is probably to test it and use trace("b.x="+b.x);
as a side note, in java for example it is impossible to pass an object by value, (or rather, the value of the object is always its memory address)

This topic is closed to new replies.

Advertisement