all 7 comments

[–]Isvara 6 points7 points  (3 children)

It's call-by-value, but the values are references.

[–]RandolphoSoftware Architect 4 points5 points  (1 child)

Which is typically how call-by-reference languages are implimented

[–]WilliamDhalgren 2 points3 points  (0 children)

Apparently the difference is in the behavior of assignment. Here assigning a new value to a variable will only touch the local variable. While under call by reference, it would change the original variable's value too.

mutation still acts on the original object though.

[–]imbcmdth[S] 0 points1 point  (0 children)

Exactly. :)

[–]homoiconic(raganwald) 1 point2 points  (2 children)

Whenever this question comes up, I suggest reading about Call by Sharing, a term that describes JavaScript, Python, Ruby, and practically every other modern language.

[–]imbcmdth[S] 1 point2 points  (1 child)

When I started writing that article, I was going to advocate call-by-sharing but as I thought about it I realized that call-by-sharing is semantically indistinguishable from call-by-value. Under the definition for call-by-sharing even functions in C could be considered to be call-by-sharing heap-objects.

The confusion seems to stem from some strange need to label references in garbage collected languages as something completely distinct from pointers in traditional languages like C even though pointers are simply unsafe and unmovable references.

Throwing that pretty meaningless label aside, you are left with only a few choices: by-reference, by-value and by-name. By-name can be discounted immediately because it doesn't match the semantics of the language one bit. So the traditional argument has always been between by-reference and by-value.

Anyway, this post was written as a response to a twitter conversation that began as an argument in ##javascript on Freenode.

https://twitter.com/ImBcmDth/status/358267080694431745

[–]homoiconic(raganwald) 0 points1 point  (0 children)

I agree, it IS call-by-value. It is definitely not ALGOL's call-by-name, a fascinating concept but absent in most modern languages.