HN2new | past | comments | ask | show | jobs | submitlogin

Are you saying that JS implementations somehow know whether the array is used to store immutable values, and will switch implementations to allow for sharing?


In JS, primitives are immutable -- number, functions (but not the fn object), regex, strings, and booleans. All other types are not immutable -- Object, Array (actually an Object), Map, Set, TypedArray, etc. Even if a linked list were added, it would not be immutable.

That said, JS has Object.freeze() which can make an object immutable. You could do this recursively to make a guaranteed immutable object. Immutable libraries in JS tend to use other methods for performance reasons though IIRC.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: