4 ms·
I would argue that Javascript is a hybrid of pass by reference because of the case below though. function someFunc(v) { v.myvar = 456; v = some
by u02sgb 6y ago
I would argue that Javascript is a hybrid of pass by reference because of the case below though.
function someFunc(v) {
v.myvar = 456;
v = someOtherObject;
}
var foo = someObject;
foo.myvar = 123;
someFunc(foo);
// foo still refers to someObject
// foo.myvar is 456
Banning our team from passing objects around except in specific, discussed, cases got rid of lots of difficult to track down bugs.
- asiachick 6y agoYou'd be wrong. Again "Pass by reference" is "well defined" in computer languages. Passing a reference to an object is not "pass by reference". Your example works the same in Java and C# and probably Swift and many other languages. But you aren't "passing by reference". "pass by reference" specifically means passing a reference to the variable, not the variable's value. Javascript always passes the value of the variable, it has no ability to pass a variable by reference.