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

154
Vistas
Javascript Map Set object reference: is this a standard to the language?

I have tested this code

const map1 = new Map();
let foo = function() {
  this.test = 1;
}
let foo2 = new foo();
map1.set('bar', foo2);

foo2.test = 2;
console.log(map1.get('bar').test);
// prints 2, not 1

on the code snippet section of

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/set

However this behavior is not specified anywhere in the same document and I couldn't find any other reference by googling.

Notice that in the Map.get document, it is stated clearly that

If the value that is associated to the provided key is an object, then you will get a reference to that object and any change made to that object will effectively modify it inside the Map object.

My question is, is the above Map.set behavior guaranteed to work in all implementations and all versions of javascript, or is the behavior not really standardized and can vary between versions.

about 4 years ago · Juan Pablo Isaza
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