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

165
Vistas
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 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