I have a class like:
var TTable = function(name){
this.props= function(){
this.properties=new TProperty();
this.properties.Add("wfstart","Workflow start","L",false);
this.properties.Add("wfend","Workflow end","L",false);
}
this.props();
}
I'd like to extend the TTable later with a new row of code in the props function like:
function addfeat(){
//Add features
var origprop = TTable.props;
Reflect.defineProperty(TTable.prototype, 'props', { value: function() {
origprop();
this.properties.Add("ttype","Tipus","N",false);
}});
}
So in my mind when I instantiate the TTable will be like this:
var TTable = function(name){
this.props= function(){
this.properties=new TProperty();
this.properties.Add("wfstart","Workflow start","L",false);
this.properties.Add("wfend","Workflow end","L",false);
this.properties.Add("ttype","Tipus","N",false);
}
this.props();
}
But the first code not working. Please help me.
You're modifying
TTable.prototype.props, but your class isn't actually using that prototype when it creates apropsfunction for every instance. It shouldn't be doing that:With this, your approach would actually work, given a few other fixes: