Would there be any way, to add another property to this object inside this function (used as a class):
function DP() {
var _this = this;
this.displayTypes = {
normal: function(div) { _this.displayNormal(div) },
round: function(div) { _this.displayRound(div) }
}
this.displayNormal = function(div) { ... };
this.displayRound = function(div) { ... };
this.display = function(div, type) {
this.displayTypes[type](div);
}
}
var dp = new DP();
// Now here I'd basically like to add another property to the DP.displayTypes
// called "rect" referencing to a function in a different class called
// DPExtension.displayRect(). So something like this:
// rect: function(div) { DPExtension.displayRect(div) }
So that I could call a dp.display("place-to-display", "rect") and that it would then execute displayRect("place-to-display") from the DPExtension class/function basically, whilst calling something like dp.display("place-to-display", "round") would execute a displayRound("place-to-display") from DP instead.
How does one do that? I tried doing some things with prototype but to no avail...
displayRectis a method and not just a function, then you need to mention the object it is attached to somewhere in your code.DPfunction, (outside it) thethisvalue inside that function will refer to it.