I have this JavaScript:
var Type = function(name) {
this.name = name;
};
var t = new Type();
Now I want to add this:
var wrap = function(cls) {
// ... wrap constructor of Type ...
this.extraField = 1;
};
So I can do:
wrap(Type);
var t = new Type();
assertEquals(1, t.extraField);
[EDIT] I'd like an instance property, not a class (static/shared) property.
The code executed in the wrapper function should work as if I had pasted it into the real constructor.
The type of Type
should not change.
Type
insidewrap()
function. For example:var wrap = function(cls) { cls.prototype.extraField=1; };
? Or may be is best to create newType2
inherited fromType
with additionalextraField
member? – Megrim