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

128
Visualizações
Can I perfectly clone any ordinary object?

I want to write a cloneDeep function that clones any JS object. There are two distinct problems here:

  1. Self references.
  2. Exotic objects.

I want to focus on the latter. Exotic objects in ECMAScript are listed in this section: 10.4 Built-in Exotic Object Internal Methods and Slots. There, it mentions exotic objects like strings, bound functions, Arrays etc. Specifically, it does not mention RegExp.

So, my expectation was that given RegExp is an ordinary object, if I copy all its own properties (enumerable and non-enumerable) and its prototype, it will behave like the source RegExp object. But that is not true: it fails when I try to access the getter regex.source by explicitly saying it is not a RegExp object.

Digging further, I found that some user-inaccessible internal slots exist in ECMAScript for various objects only to be accessible through their constructors.

This leads me to believe either of the two is true:

  1. RegExp is also an exotic object somehow.
  2. It is an ordinary object but there is some other state I did not copy.

Which one of these is true? Because I am not able to wrap my head around an ordinary object with object-specific internal slots.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It is an ordinary object with some internal state that you could not copy.

Being an exotic object only means that it has some extraordinary implementation of the internal methods, not that it doesn't have any internal slots. Many builtin functions - such as the .source getter you describe - still require being called on an object with specific internal slots.

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