Shallow Copy
Learn about cloning objects and the concept of shallow copy.
We'll cover the following
Introduction
JavaScript made its way from being a toy language for simple animations to becoming a language for client-side and server-side web application development. Some generic concepts also made their way to the JavaScript world, and developers became more and more aware of them. Cloning objects is one of these concepts.
Cloning can be quite complex. Prototypal inheritance, reference types, and methods associated with an object may require a specialized approach. Restrictions on cloned data may simplify cloning. It is the responsibility of the developers to understand and apply the correct cloning method on a case-by-case basis.
Shallow Copy:
Cloning methods of most libraries are implemented using shallow copying. One example is _.clone
, the clone method of UnderscoreJs.
All field keys and values of the original object are copied to the new object.
Get hands-on with 1400+ tech skills courses.