Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

128
Vistas
Tuples/ Records in JavaScript

I was referring to this link: Future Javascript: Records and Tuples and I was wondering, what is the reasoning behind these?

We can still use Object.freeze with both arrays and objects to achieve this. Only reasoning I can think of is compare by value. So this will allow us to have complex object like structure(records) in Set as keys and we can fetch them without much hassle. But does this look big enough reason to add new datatype in a language?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Object.freeze protects writing access just at an object's first (entry/property) level. Any structure nested deeper than 1 is writable. Thus a frozen object never is deeply frozen.

In order to achieve the latter one has to write ones' own recursive deepFreeze function.

In contrast the future primitive Record and Tuple values are truly/entirely immutable.

const wellTempered = {
  foo: {
    bar: 'baz',
    biz: {
      buzz: 'booz',
    },
  },
  safe: 'protected',
};
const frozen = Object.freeze(wellTempered);

console.log(
  '(wellTempered === frozen) ?..',
  (wellTempered === frozen),
);

// - level 1 is frozen, thus not writable.
// - writing attempts will fail silently
//   in non strict mode.

frozen.safe = 'vulnerable';

// - `freeze` doesn't freeze deeply.
//
// - nested levels deeper than 1
//   are still writable.

frozen.foo.bar = "fooled";
frozen.foo.biz.buzz = "doomed";

console.log({
  wellTempered,
  frozen,
});
.as-console-wrapper { min-height: 100%!important; top: 0; }

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda