Document class inheritance approach
I am trying to implement a CustomDoc class that inherits from the document class. For example, something like the following:
var CustomDoc = function(doc){
/* Code to inherit properties and methods of Document class and
set the properties to those in doc */
this.exportPng = function(){
/* Method that exports the current document */
};
};
var currentDoc = new CustomDoc(app.activeDocument);
currentDoc.pathItems.removeAll(); //pathItems as example inherited property
currentDoc.exportPng(); //Custom function defined in CustomDoc
I'm not sure exactly how to do this. For one thing, the Document class does not have a constructor, so I can't do something like this:
var CustomDoc = function(doc){ Document.call() };
Nor can I do something like this:
CustomDoc.prototype = Document.create();
What I can do is add methods to an existing Document object, such as activeDocument:
activeDocument.customMethod = function(){
/* Body */
};
This might work, but it's not really how I'd prefer to design things. For example, if I create the variable newDoc in the example below, it won't have the properties or methods of activeDocument:
var newDoc = app.documents.add();
Rather, I would like to be able to do the following:
var newDoc = new CustomDoc(app.documents.add());
Does anyone have recommendations on how to go about this? Many thanks in advance.