Ad
  • Custom User Avatar

    Best of the best is COBOL:

          CALL "MY-BLOODY-FUNCTION" USING BY CONTENT TABLE-OF-STUFF
                                          BY REFERENCE TABLE-MUTABLE
    

    (works with numbers, strings... whatever)

  • Default User Avatar

    I think we both understand how parameters are passed in JS, we just disagree on the terminology. It sounds silly to me to say that an object is "passed by value" when I can mutate the original object from within the function (i.e. the function has side effects).

    Going by your definition, only languages like PHP have something like "passing by reference", where using the assignment operator (=) affects the original variable.
    I think a better term for how objects are passed in JS / Python / Java ... is 'call by sharing'.

    If you say that in JS, both Numbers and Objects are passed by value, it sounds really misleading with regard to purity and side effects : in one case the function is pure, in the other it's not, and you have to watch out for mutation when you pass your object to a function.

    Anyway, let's not bicker about it, I dont want to argue endlessly on terminology, as long as we both understand what's happening.

  • Custom User Avatar
  • Default User Avatar

    you CAN change the object passed to your function precisely because it is passed by reference, not by value ...

  • Default User Avatar

    JS parameters are always passed by value

    are they really ?

    function modify (array) { array[0] = "mutated !" };
    const array = ["hello world"];
    modify(array);
    console.log(array[0]); // 'mutated !'
    

    objects are passed by a copy of the reference. this means reassigning to the parameter will indeed have no effect on the original object; however, modifying the object's properties will affect the original object

  • Default User Avatar

    Yes It happen before. People think that magazine is like journals or stuff to read. But in this context is slots for the weapons.

    O ponto é que você deve descobrir quantos pentes cada agente do bope deve possuir em uma determinada missão. A palavra magazines é relacionada a pentes (balas) e não a revistas.

    Por isso a cada rua que eles cruzam, eles atiram. Entendeu?

  • Custom User Avatar

    A magazine is a part of a gun that includes bullets. I was confused by this word (magazine) because I knew only one meaning of this word. It's a quite easy kata.