News for hackers. Stuff that matters.
Re:Deep-copying in JavaScript by zzzcpan on Thursday January 25, 2018 @03:42PM (#16234458)
From a user perspective most languages make a mess out of these things and confuse people. In Javascript certain things are declared in a similar way, but some behave like values and some behave like references. Which makes it both pass-by-value and pass-by-reference.
Re:Deep-copying in JavaScript by pjmlp on Thursday January 25, 2018 @03:58PM (#16234604)
Wrong from CS point of view, references are also pass-by-value on JavaScript.

If JavaScript allowed pass-by-referece, we would be able to do the following,

    function swap(x, y) {
        let c = x
        x = y
        y = c
    }

    let a = {a: 6, b: 7}
    let b = {c: 8, d: 8}

    swap(a, b)

    console.log(b)

    // Object {a: 6, b: 7}
Meaning, pass-by-reference means being able to actually change the "pointer" used by the local variable.
Re:Deep-copying in JavaScript by zzzcpan on Thursday January 25, 2018 @04:11PM (#16234714)
I understand what you mean, but consider this to be an incorrect view on these things. They are not about CS, but about user experience.
Re:Deep-copying in JavaScript by pjmlp on Thursday January 25, 2018 @05:08PM (#16235159)
The incorrect view is to teach wrong concepts just because some people rather learn based on gut feeling, than taking the effort to learn it properly.
Re:Deep-copying in JavaScript by shkkmo on Thursday January 25, 2018 @03:56PM (#16234586)
I believe that javascript always uses pass-reference-by-value, but simple types are immutable, which means that pass-reference-by-value is functionally identical to pass-by-value since there is no way to make changes to the immutable referent.