Cloning modules
Cloning objects in general, and cloning modules in particular, is about creating an exact replica of the original object or module.
But before we talk about cloning, let's consider some of the ways that we can create new objects based on other objects.
Creating instances of a constructor function
One way of creating objects based on another object is by creating instances of a constructor function.
As you know, when we create an instance of an object using a constructor function in JavaScript, we use the new
keyword. The created instance resides in a different memory address than the constructor function. When we assign properties to the prototype
property of the constructor function, all the instances of the constructor function will share these properties of the prototype
object.
Let's have a look at a simple example and review creating objects based on constructor functions.
Consider the following code snippet:
function testConstructor (){ this.someValue = "Value in the...