I am working with an object that has the following structure:
var customObject = function() {
this.property = "value";
};
customObject.prototype = new otherObject();
customObject.prototype.property2 = function() {};
This is just a snippet as the actual object is quite extensive.
Currently, I can successfully create an instance of this object by using new customObject()
.
Now, I want to develop a similar but slightly modified version of this object. This would involve tweaking certain properties and potentially adding or removing some as well. Similar to the original object, I want it to be instantiated with new customObject2()
.
The approach I initially considered was:
var customObject2 = new customObject();
customObject2.prototype = customObject.prototype;
customObject2.property = "modified value";
However, when attempting to instantiate it with new customObject2()
, I encounter an error indicating that customObject2 is not a function.
I hope this explanation clarifies the pattern I aim to establish. Can you suggest how I should go about creating such a pattern?