How to extend/add additional functionality (to) an InDesign class like Cell
Hello,
I am trying to add some extra functionality to every instance of e.g. the Cell 'class' of InDesign using Javascript. I started doing something like this:
Cell.prototype.newFunction = function() { ....... }
which works fine: it is now possible to call newFunction() on every instance of Cell.
But now I would like to let this function (that I've added to the prototype chain of Cell like shown above and thus is also available for an 'instance' of Cell) use a 'variable' that is specific for every Cell instance, e.g.:
Cell.prototype.getSuperValue = function ()
{
if (this._cachedValue === undefined)
{
this._cachedValue = 3; // doing some incredible calculations that take some time
}
return this._cachedValue;
};
The this._cachedValue should be a attribute of the Cell instance. So if I take to cells from a Table and I call getSuperValue() on them I can get two different values that are specific for every instance of Cell.
Thanks a lot in advance!
![]()
P.S. although I am quite new to Javascript I know there are no classes in Javascript and that Cell is an object. But I thought explaining it like this would make it more clear?
