I'm looking to do something a little bit fancy with constructor functions in Javascript, and I'm not quite sure how to do it.
I want to be able to define Constructor functions, and then pass them into another function (a "modifer") like this:
function OriginalConstructor() {
// Do constructor things here
// Like defining methods and properties
}
NewConstructor = modifyConstructor(OriginalConstructor);
And the resulting "NewConstructor" should be functionally equivalent to this:
function NewConstructor(id, data) {
this.id = id;
this.data = data;
// Do stuff from the original constructor here
// i.e. the same methods and properties defined in the original constructor
}
Does anybody know how to go about creating the "modifyConstructor" function?