Pass-by-value vs. Pass-by-reference #60

battre opened this Issue Mar 21, 2011 · 1 comment


None yet

3 participants

battre commented Mar 21, 2011

In the context of the "Avoiding the reference problem" it might be interesting to point out that the presented approach does not work for objects:
function foo(x) {
// x is a copy of y but points to the same object
x.test = 42;
console.log(x.test); // prints 42
var y = {};
console.log(y.test); // prints 42


I think it's more a problem of bad wording. It actually works like expected. You're still passing a value in there, it's just a "pointer" to the object. So you get a copy of the pointer, which in this case will resolve to the same object.

So a change in wording might be a good idea, I'm really busy at the moment with the job / finding a shared flat etc. So feel free to write something up and file a pull request that I can review!

@timruffles timruffles closed this Apr 30, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment