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

169
Visualizações
How do you construct an object that behaves like a lazily-evaluated deep merge of two other objects in JavaScript?

How do you write a function lazyDeepMerge(object1, object2) which constructs and returns some object lazyObject such that whenever lazyObject is queried for a the value of a property someProp, the value returned behaves exactly the same as the value returned by calling regularDeepMerge(object1, object2).someProp?

As background, deep merging two objects (recursively merging their respective properties) has been addressed here: How to deep merge instead of shallow merge?

The difference between lazyDeepMerge and regular deepMerge() would be that the lazy one would not do any merging of values in advance.

For example, calling lazyObject.vehicles.camry.color would merge what’s needed in order to return a value identical to the one returned from calling eagerObject.vehicles.camry.color.

The process would be that calling lazyObject.vehicles would return an object lazyVehicles. If you then called lazyVehicles.camry.color, lazyVehicles would lazily merges what's necessary to return the value, and that value may be another lay object, etc.

Any solution would probably have to make use of the JavaScript Proxy object, which is very straightforward to use - so that’s not an issue I need to solve.

An ideal solution would involve caching the values of properties the first time they’re looked up, as well as the ability to pass in a custom merge(obj1, obj2) function (like with the Lodash library function _.mergeWith(object, sources, customizer))

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