|
|
|
|
|
by DougBTX
227 days ago
|
|
> I want everything that passes through a function to be a copy unless I put in a symbol or keyword that it suppose to be passed by reference. JavaScript doesn’t have references, it is clearer to only use “passed by reference” terminology when writing about code in a language which does have them, like C++ [0]. In JavaScript, if a mutable object is passed to a function, then the function can change the properties on the object, but it is always the same object. When an object is passed by reference, the function can replace the initial object with a completely different one, that isn’t possible in JS. Better is to distinguish between immutable objects (ints, strings in JS) and mutable ones. A mutable object can be made immutable in JS using Object.freeze [1]. [0] https://en.wikipedia.org/wiki/Reference_(C%2B%2B) [1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... |
|
Maybe someone should work on a way to make references in javascript land. Sort of like immer but baked in.
https://immerjs.github.io/immer/