Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

159
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda