0 Replies Latest reply on Apr 5, 2009 2:43 PM by Weller_UK_

    JS How to pass arguments to "ancestor's" methods?

      I'm scripting Adobe InDesign via JS.

      I've created custom 'Classes' for custom InDesign objects.
      They all inherit common methods from generic 'Item' class.

      Now the problem is that most of these methods need acces to the arguments of the child's constructor. I know this may sound convoluted, please refer to the example:

      /* Generic object, containig common methods */
      function Item(){     
                 this.geometricBounds = function(){
                     /*relies on this.item from the child object*/

      /* Specific object, inheriting from Item() */
      function Box(item){
                 this.constructor = Box;     

                  /* creates this.item so that ancestor can use it in it's methods */
                 this.item = item;

      Box.prototype = new Item();

      // Example of use

      a = new Box(app.selection[0])

      As you can see there is a workaround. I'm just not entirely happy with "this.item = item" in the Box()'s constructor. I have to repeat this line in every constructor function that is inheriting from Item().

      So I wonder wheter there's another way to make ancestor's method aware of their child's variables.

      Thanks for help
      Weller_UK is online now Report Post  Edit/Delete Message